{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "021f39c4-1197-4dc2-aaa9-5a8ef16b9ed5",
   "metadata": {},
   "source": [
    "# Tushare数据获取"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83fe66c4-e835-4942-baca-bf7163f9455d",
   "metadata": {},
   "source": [
    "## 三行代码获取Tushare数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "407ec00b-237f-4fb6-949c-1e53a5c4940a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "02b67028-49c1-4568-8425-887c08453198",
   "metadata": {},
   "outputs": [],
   "source": [
    "pro = ts.pro_api('a07f9b518030d3b7aa22c3642bb9dd2681a53701c403b7dad7a9ec46')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "72d78ddf-8489-4d42-a789-f9377901cb47",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42efadf6-d458-44f8-af7e-c6932dbda0c0",
   "metadata": {},
   "source": [
    "## 介绍代码信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b1c1e00f-f2b7-4036-bca3-5009053d8994",
   "metadata": {},
   "source": [
    "上面的代码中：\n",
    "- 导包：import 是 导包语句 \n",
    "- 别名：as 后跟别名 tushare => ts\n",
    "- 功能：pro_api 是 ts 这个对象的一个功能， ts如果是人， pro_api可以是吃饭、睡觉、学习\n",
    "- 参数：功能的里面需要传参数，pro_api传的就是一个token，stock_basic里面穿的就是一系列的条件\n",
    "- 字符串：python中用' ' 或 \" \" 中间包起来字符串\n",
    "- 变量：ts.pro_api => pro，下面我们就可以用pro去代替前面的所有功能\n",
    "- 注释： # "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc26b193-8da2-4254-a8d4-4bb9346f562f",
   "metadata": {},
   "source": [
    "## 测试token更新的影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "473fbe3e-f0f6-4a9c-b982-a7d3da64c8f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "old_token = 'a07f9b518030d3b7aa22c3642bb9dd2681a53701c403b7dad7a9ec46'\n",
    "new_token = '9b06a5d7c1e9b0cbc3e0d666adde265dc717535df8cb2c8474f3c06e'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0d7b7df0-c818-4e3c-9f27-2038b5e90a4f",
   "metadata": {},
   "outputs": [
    {
     "ename": "Exception",
     "evalue": "抱歉，您输入的TOKEN无效！",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_12464/380758500.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#查询当前所有正常上市交易的股票列表\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpro\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstock_basic\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexchange\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m''\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlist_status\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'L'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfields\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'ts_code,symbol,name,area,industry,list_date'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\tushare\\pro\\client.py\u001b[0m in \u001b[0;36mquery\u001b[1;34m(self, api_name, fields, **kwargs)\u001b[0m\n\u001b[0;32m     42\u001b[0m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     43\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'code'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 44\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'msg'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     45\u001b[0m             \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'data'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     46\u001b[0m             \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'fields'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mException\u001b[0m: 抱歉，您输入的TOKEN无效！"
     ]
    }
   ],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "pro = ts.pro_api(old_token)\n",
    "data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "02714e5b-82e4-486e-a56f-b31dc8ffd9f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>list_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国华网安</td>\n",
       "      <td>深圳</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>19920427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4765</th>\n",
       "      <td>871642.BJ</td>\n",
       "      <td>871642</td>\n",
       "      <td>通易航天</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20210816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4766</th>\n",
       "      <td>871857.BJ</td>\n",
       "      <td>871857</td>\n",
       "      <td>泓禧科技</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20220228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4767</th>\n",
       "      <td>871981.BJ</td>\n",
       "      <td>871981</td>\n",
       "      <td>晶赛科技</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20211115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4768</th>\n",
       "      <td>872925.BJ</td>\n",
       "      <td>872925</td>\n",
       "      <td>锦好医疗</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20211025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4769</th>\n",
       "      <td>689009.SH</td>\n",
       "      <td>689009</td>\n",
       "      <td>九号公司-WD</td>\n",
       "      <td>北京</td>\n",
       "      <td>摩托车</td>\n",
       "      <td>20201029</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4770 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ts_code  symbol     name  area industry list_date\n",
       "0     000001.SZ  000001     平安银行    深圳       银行  19910403\n",
       "1     000002.SZ  000002      万科A    深圳     全国地产  19910129\n",
       "2     000004.SZ  000004     国华网安    深圳     软件服务  19910114\n",
       "3     000005.SZ  000005     ST星源    深圳     环境保护  19901210\n",
       "4     000006.SZ  000006     深振业A    深圳     区域地产  19920427\n",
       "...         ...     ...      ...   ...      ...       ...\n",
       "4765  871642.BJ  871642     通易航天  None     None  20210816\n",
       "4766  871857.BJ  871857     泓禧科技  None     None  20220228\n",
       "4767  871981.BJ  871981     晶赛科技  None     None  20211115\n",
       "4768  872925.BJ  872925     锦好医疗  None     None  20211025\n",
       "4769  689009.SH  689009  九号公司-WD    北京      摩托车  20201029\n",
       "\n",
       "[4770 rows x 6 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "pro = ts.pro_api(new_token)\n",
    "data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe2945ce-02e7-46b2-98b4-8315794ff5c1",
   "metadata": {},
   "source": [
    "## 测试获取更多的维度数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "088ee83b-72e2-4f3c-9b7c-797c1e0c29d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>list_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国华网安</td>\n",
       "      <td>深圳</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>19920427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4765</th>\n",
       "      <td>871642.BJ</td>\n",
       "      <td>871642</td>\n",
       "      <td>通易航天</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20210816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4766</th>\n",
       "      <td>871857.BJ</td>\n",
       "      <td>871857</td>\n",
       "      <td>泓禧科技</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20220228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4767</th>\n",
       "      <td>871981.BJ</td>\n",
       "      <td>871981</td>\n",
       "      <td>晶赛科技</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20211115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4768</th>\n",
       "      <td>872925.BJ</td>\n",
       "      <td>872925</td>\n",
       "      <td>锦好医疗</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20211025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4769</th>\n",
       "      <td>689009.SH</td>\n",
       "      <td>689009</td>\n",
       "      <td>九号公司-WD</td>\n",
       "      <td>北京</td>\n",
       "      <td>摩托车</td>\n",
       "      <td>20201029</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4770 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ts_code  symbol     name  area industry list_date\n",
       "0     000001.SZ  000001     平安银行    深圳       银行  19910403\n",
       "1     000002.SZ  000002      万科A    深圳     全国地产  19910129\n",
       "2     000004.SZ  000004     国华网安    深圳     软件服务  19910114\n",
       "3     000005.SZ  000005     ST星源    深圳     环境保护  19901210\n",
       "4     000006.SZ  000006     深振业A    深圳     区域地产  19920427\n",
       "...         ...     ...      ...   ...      ...       ...\n",
       "4765  871642.BJ  871642     通易航天  None     None  20210816\n",
       "4766  871857.BJ  871857     泓禧科技  None     None  20220228\n",
       "4767  871981.BJ  871981     晶赛科技  None     None  20211115\n",
       "4768  872925.BJ  872925     锦好医疗  None     None  20211025\n",
       "4769  689009.SH  689009  九号公司-WD    北京      摩托车  20201029\n",
       "\n",
       "[4770 rows x 6 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1918a417-2a90-4fe4-89cc-3cc1e94ea8b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>fullname</th>\n",
       "      <th>enname</th>\n",
       "      <th>cnspell</th>\n",
       "      <th>market</th>\n",
       "      <th>exchange</th>\n",
       "      <th>curr_type</th>\n",
       "      <th>list_status</th>\n",
       "      <th>list_date</th>\n",
       "      <th>delist_date</th>\n",
       "      <th>is_hs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>平安银行股份有限公司</td>\n",
       "      <td>Ping An Bank Co., Ltd.</td>\n",
       "      <td>payh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910403</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>万科企业股份有限公司</td>\n",
       "      <td>China Vanke Co.,Ltd.</td>\n",
       "      <td>wka</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910129</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国华网安</td>\n",
       "      <td>深圳</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>深圳国华网安科技股份有限公司</td>\n",
       "      <td>Shenzhen Guohua Network Security Technology Co...</td>\n",
       "      <td>ghwa</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910114</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>深圳世纪星源股份有限公司</td>\n",
       "      <td>Shenzhen Fountain Corporation</td>\n",
       "      <td>stxy</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901210</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>深圳市振业(集团)股份有限公司</td>\n",
       "      <td>Shenzhen Zhenye(Group) Co.,Ltd.</td>\n",
       "      <td>szya</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19920427</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4765</th>\n",
       "      <td>871642.BJ</td>\n",
       "      <td>871642</td>\n",
       "      <td>通易航天</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>南通通易航天科技股份有限公司</td>\n",
       "      <td>Nantong Tongyi Aerospace Science and Technolog...</td>\n",
       "      <td>tyht</td>\n",
       "      <td>北交所</td>\n",
       "      <td>BSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20210816</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4766</th>\n",
       "      <td>871857.BJ</td>\n",
       "      <td>871857</td>\n",
       "      <td>泓禧科技</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>重庆市泓禧科技股份有限公司</td>\n",
       "      <td>Chongqing Hong Xi Technology Co.,Ltd.</td>\n",
       "      <td>hxkj</td>\n",
       "      <td>北交所</td>\n",
       "      <td>BSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220228</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4767</th>\n",
       "      <td>871981.BJ</td>\n",
       "      <td>871981</td>\n",
       "      <td>晶赛科技</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>安徽晶赛科技股份有限公司</td>\n",
       "      <td>Anhui Jing Sai Technology Co., Ltd</td>\n",
       "      <td>jskj</td>\n",
       "      <td>北交所</td>\n",
       "      <td>BSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20211115</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4768</th>\n",
       "      <td>872925.BJ</td>\n",
       "      <td>872925</td>\n",
       "      <td>锦好医疗</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>惠州市锦好医疗科技股份有限公司</td>\n",
       "      <td>Huizhou Jinghao Medical Technology Co.,Ltd.</td>\n",
       "      <td>jhyl</td>\n",
       "      <td>北交所</td>\n",
       "      <td>BSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20211025</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4769</th>\n",
       "      <td>689009.SH</td>\n",
       "      <td>689009</td>\n",
       "      <td>九号公司-WD</td>\n",
       "      <td>北京</td>\n",
       "      <td>摩托车</td>\n",
       "      <td>九号有限公司</td>\n",
       "      <td>Ninebot Limited</td>\n",
       "      <td>jhgs-wd</td>\n",
       "      <td>CDR</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20201029</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4770 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ts_code  symbol     name  area industry         fullname  \\\n",
       "0     000001.SZ  000001     平安银行    深圳       银行       平安银行股份有限公司   \n",
       "1     000002.SZ  000002      万科A    深圳     全国地产       万科企业股份有限公司   \n",
       "2     000004.SZ  000004     国华网安    深圳     软件服务   深圳国华网安科技股份有限公司   \n",
       "3     000005.SZ  000005     ST星源    深圳     环境保护     深圳世纪星源股份有限公司   \n",
       "4     000006.SZ  000006     深振业A    深圳     区域地产  深圳市振业(集团)股份有限公司   \n",
       "...         ...     ...      ...   ...      ...              ...   \n",
       "4765  871642.BJ  871642     通易航天  None     None   南通通易航天科技股份有限公司   \n",
       "4766  871857.BJ  871857     泓禧科技  None     None    重庆市泓禧科技股份有限公司   \n",
       "4767  871981.BJ  871981     晶赛科技  None     None     安徽晶赛科技股份有限公司   \n",
       "4768  872925.BJ  872925     锦好医疗  None     None  惠州市锦好医疗科技股份有限公司   \n",
       "4769  689009.SH  689009  九号公司-WD    北京      摩托车           九号有限公司   \n",
       "\n",
       "                                                 enname  cnspell market  \\\n",
       "0                                Ping An Bank Co., Ltd.     payh     主板   \n",
       "1                                  China Vanke Co.,Ltd.      wka     主板   \n",
       "2     Shenzhen Guohua Network Security Technology Co...     ghwa     主板   \n",
       "3                         Shenzhen Fountain Corporation     stxy     主板   \n",
       "4                       Shenzhen Zhenye(Group) Co.,Ltd.     szya     主板   \n",
       "...                                                 ...      ...    ...   \n",
       "4765  Nantong Tongyi Aerospace Science and Technolog...     tyht    北交所   \n",
       "4766              Chongqing Hong Xi Technology Co.,Ltd.     hxkj    北交所   \n",
       "4767                 Anhui Jing Sai Technology Co., Ltd     jskj    北交所   \n",
       "4768        Huizhou Jinghao Medical Technology Co.,Ltd.     jhyl    北交所   \n",
       "4769                                    Ninebot Limited  jhgs-wd    CDR   \n",
       "\n",
       "     exchange curr_type list_status list_date delist_date is_hs  \n",
       "0        SZSE       CNY           L  19910403        None     S  \n",
       "1        SZSE       CNY           L  19910129        None     S  \n",
       "2        SZSE       CNY           L  19910114        None     N  \n",
       "3        SZSE       CNY           L  19901210        None     N  \n",
       "4        SZSE       CNY           L  19920427        None     S  \n",
       "...       ...       ...         ...       ...         ...   ...  \n",
       "4765      BSE       CNY           L  20210816        None     N  \n",
       "4766      BSE       CNY           L  20220228        None     N  \n",
       "4767      BSE       CNY           L  20211115        None     N  \n",
       "4768      BSE       CNY           L  20211025        None     N  \n",
       "4769      SSE       CNY           L  20201029        None  None  \n",
       "\n",
       "[4770 rows x 15 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "all_fields = 'ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs'\n",
    "data = pro.stock_basic(exchange='', list_status='L', fields=all_fields)\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c489c010-243d-41ee-b0d4-3478a81edf96",
   "metadata": {},
   "source": [
    "## 导出我们获取的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "92c3f66f-eae3-4ff9-b455-248c48840e8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.columns = ['TS代码', '股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写', '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期', '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "f2e66e2b-a0ed-4330-8477-59ebc3caed3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "tmp = data.iloc[:5, :4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "d949671e-3276-4869-8d0d-0b9c53bf74d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    000001.SZ\n",
       "1    000002.SZ\n",
       "2    000004.SZ\n",
       "3    000005.SZ\n",
       "4    000006.SZ\n",
       "Name: TS代码, dtype: object"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tmp.iloc[:, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a6969dd4-e609-42a9-8260-7d6ec951ad11",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_excel('上市公司基本信息-220404.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09de4ed5-f26c-4f86-bcba-77c516dd401d",
   "metadata": {},
   "source": [
    "# Pandas介绍"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5fd07a11-6562-4087-bcb5-2c820a3a1a2c",
   "metadata": {},
   "source": [
    "## Pands的前世今生"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d611a0c1-fdbe-45ac-883a-edbaade544a6",
   "metadata": {},
   "source": [
    "## Pandas的DataFrame和Series"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2e4fa16-a3dc-4b69-9518-4b0b3bef4baf",
   "metadata": {},
   "source": [
    "### DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d4d51555-ab1c-437d-a53e-e1d0d2f31aa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "d8b01845-e46a-49e5-81a7-a6acd292f450",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   a  b  c\n",
       "1  1  2  3\n",
       "2  4  5  6"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data=[[1,2,3],[4,5,6]], index=[1, 2], columns=['a', 'b', 'c'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "f1fd65a2-6e74-4182-9b8b-2600e4e527a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['a', 'b', 'c'], dtype='object')"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "3e3d0df9-1e25-4a1c-b522-a2e7da2b389d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([1, 2], dtype='int64')"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "802c4197-69bf-41ee-b2a5-41f7f65a36ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]], dtype=int64)"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6da89aa6-c78c-4ef4-859a-74db1714b19d",
   "metadata": {},
   "source": [
    "### Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "93ae4aa3-079c-4032-8865-eb0875c7de9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    100\n",
       "2    200\n",
       "dtype: int64"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series = pd.Series(data=[100, 200], index=[1, 2])\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "96b10b04-3c48-4bc2-a65f-08409996e865",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([1, 2], dtype='int64')"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "74953551-f9eb-446f-98bf-19eeeb0a8097",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([100, 200], dtype=int64)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "533923a9-e349-4839-b89f-5cce3dcc36ad",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Series' object has no attribute 'columns'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_12464/136159008.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mseries\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m   5485\u001b[0m         ):\n\u001b[0;32m   5486\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 5487\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   5488\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   5489\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'Series' object has no attribute 'columns'"
     ]
    }
   ],
   "source": [
    "series.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60160953-f53f-414f-9a69-7cc7cd4e9a0a",
   "metadata": {},
   "source": [
    "### 属性和方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79cbbfbf-790a-4429-8a69-b28a6064cc28",
   "metadata": {},
   "source": [
    "#### 属性后面不加括号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ae246f35-7bd3-43fe-9808-704d93b3c7bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=4770, step=1)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "934ff5db-1b42-49a6-832a-b53ba98ce658",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['TS代码', '股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写',\n",
       "       '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期',\n",
       "       '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "45ce8b59-aa75-409a-a1ab-1d74b3555767",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['000001.SZ', '000001', '平安银行', ..., '19910403', None, 'S'],\n",
       "       ['000002.SZ', '000002', '万科A', ..., '19910129', None, 'S'],\n",
       "       ['000004.SZ', '000004', '国华网安', ..., '19910114', None, 'N'],\n",
       "       ...,\n",
       "       ['871981.BJ', '871981', '晶赛科技', ..., '20211115', None, 'N'],\n",
       "       ['872925.BJ', '872925', '锦好医疗', ..., '20211025', None, 'N'],\n",
       "       ['689009.SH', '689009', '九号公司-WD', ..., '20201029', None, None]],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.values"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55495378-8b3c-4c1c-b42f-d8fe0b942bbc",
   "metadata": {},
   "source": [
    "#### 方法/功能/函数：后面加括号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "28e0c8c1-f817-47ce-a4e6-dc75a8593b7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>平安银行股份有限公司</td>\n",
       "      <td>Ping An Bank Co., Ltd.</td>\n",
       "      <td>payh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910403</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称  地域 所属行业        股票全称                    英文全称  拼音缩写  \\\n",
       "0  000001.SZ  000001  平安银行  深圳   银行  平安银行股份有限公司  Ping An Bank Co., Ltd.  payh   \n",
       "\n",
       "  市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "0                   主板  SZSE  CNY                  L  19910403  None   \n",
       "\n",
       "  是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "0                     S  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8c30800-a616-4b89-b8ea-b48a16f1caa1",
   "metadata": {},
   "source": [
    "## Pandas和Excel的不同点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e79d11f7-73e9-4a90-94ea-812ef66574c5",
   "metadata": {},
   "source": [
    "- 操作粒度：Excel的单个单元格操作更强，Pandas更适用于更多单元格的分析计算\n",
    "- 数据收集：Excel可对数据从0到1粘贴收集，Pandas更适用于读取已有的数据集\n",
    "- 数据文件：Excel的文件格式更通用，Pandas依赖于Python所以受众更窄\n",
    "- 展示效果：Excel的展示细节配置更灵活，Pandas依赖其他展示工具配置更统一，但也会更丰富\n",
    "- 数据量级：Pandas的上限取决于服务器的性能，Excel无法处理数据量太大的表格\n",
    "- 功能程度：Pandas依赖于Python强大的社区应用，对数据分析、建模、可视化等方面提供了强大的支撑"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90e87cfe-cc32-4760-8007-66021fb1ed1b",
   "metadata": {},
   "source": [
    "**总结**：日常小数量的电子表格用Excel。如果大数据量或需要使用VBA，在掌握python的前提下，不如用pandas。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "644a8a00-c471-418c-b630-3921836c9d1c",
   "metadata": {},
   "source": [
    "## Pandas学习经验"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0190782-e9c9-42ae-8731-e5a8a93ff2af",
   "metadata": {},
   "source": [
    "pandas中文网：https://www.pypandas.cn/"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "877ef2b8-7246-4233-9a2d-b990bc1fde12",
   "metadata": {},
   "source": [
    "**由表及里，带着场景**：  \n",
    "- Excel  -> VBA   -> VB语法\n",
    "- Pandas -> Numpy -> Python语法  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d75e543-7d44-4160-ac21-e8ee8eb979fe",
   "metadata": {},
   "source": [
    "### 寻找中国最早上市的股票"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "c20731d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>深圳世纪星源股份有限公司</td>\n",
       "      <td>Shenzhen Fountain Corporation</td>\n",
       "      <td>stxy</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901210</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3141</th>\n",
       "      <td>600651.SH</td>\n",
       "      <td>600651</td>\n",
       "      <td>飞乐音响</td>\n",
       "      <td>上海</td>\n",
       "      <td>电器仪表</td>\n",
       "      <td>上海飞乐音响股份有限公司</td>\n",
       "      <td>Shanghai Feilo Acoustics Co.,Ltd</td>\n",
       "      <td>flyx</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3143</th>\n",
       "      <td>600653.SH</td>\n",
       "      <td>600653</td>\n",
       "      <td>申华控股</td>\n",
       "      <td>辽宁</td>\n",
       "      <td>汽车服务</td>\n",
       "      <td>辽宁申华控股股份有限公司</td>\n",
       "      <td>Liaoning Shenhua Holdings Co., Ltd</td>\n",
       "      <td>shkg</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3100</th>\n",
       "      <td>600602.SH</td>\n",
       "      <td>600602</td>\n",
       "      <td>云赛智联</td>\n",
       "      <td>上海</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>云赛智联股份有限公司</td>\n",
       "      <td>INESA Intelligent Tech Inc.</td>\n",
       "      <td>yszl</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3144</th>\n",
       "      <td>600654.SH</td>\n",
       "      <td>600654</td>\n",
       "      <td>ST中安</td>\n",
       "      <td>湖北</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>中安科股份有限公司</td>\n",
       "      <td>China Security Co., Ltd</td>\n",
       "      <td>stza</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2609</th>\n",
       "      <td>301263.SZ</td>\n",
       "      <td>301263</td>\n",
       "      <td>C泰恩康</td>\n",
       "      <td>广东</td>\n",
       "      <td>医药商业</td>\n",
       "      <td>广东泰恩康医药股份有限公司</td>\n",
       "      <td>Guangdong Taienkang Pharmaceutical Co.,Ltd.</td>\n",
       "      <td>tek</td>\n",
       "      <td>创业板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220329</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4423</th>\n",
       "      <td>688193.SH</td>\n",
       "      <td>688193</td>\n",
       "      <td>仁度生物</td>\n",
       "      <td>上海</td>\n",
       "      <td>医疗保健</td>\n",
       "      <td>上海仁度生物科技股份有限公司</td>\n",
       "      <td>Shanghai Rendu Biotechnology Co., Ltd.</td>\n",
       "      <td>rdsw</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220330</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4514</th>\n",
       "      <td>688331.SH</td>\n",
       "      <td>688331</td>\n",
       "      <td>荣昌生物</td>\n",
       "      <td>山东</td>\n",
       "      <td>生物制药</td>\n",
       "      <td>荣昌生物制药(烟台)股份有限公司</td>\n",
       "      <td>Remegen Co., Ltd.</td>\n",
       "      <td>rcsw</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220331</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4315</th>\n",
       "      <td>688048.SH</td>\n",
       "      <td>688048</td>\n",
       "      <td>N华芯</td>\n",
       "      <td>江苏</td>\n",
       "      <td>半导体</td>\n",
       "      <td>苏州长光华芯光电技术股份有限公司</td>\n",
       "      <td>Suzhou Everbright Photonics Co., Ltd.</td>\n",
       "      <td>cghx</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220401</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4488</th>\n",
       "      <td>688295.SH</td>\n",
       "      <td>688295</td>\n",
       "      <td>中复神鹰</td>\n",
       "      <td>江苏</td>\n",
       "      <td>化纤</td>\n",
       "      <td>中复神鹰碳纤维股份有限公司</td>\n",
       "      <td>Zhongfu Shenying Carbon Fiber Co.,Ltd.</td>\n",
       "      <td>zfsy</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220406</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4770 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码  股票名称  地域  所属行业              股票全称  \\\n",
       "3     000005.SZ  000005  ST星源  深圳  环境保护      深圳世纪星源股份有限公司   \n",
       "3141  600651.SH  600651  飞乐音响  上海  电器仪表      上海飞乐音响股份有限公司   \n",
       "3143  600653.SH  600653  申华控股  辽宁  汽车服务      辽宁申华控股股份有限公司   \n",
       "3100  600602.SH  600602  云赛智联  上海  软件服务        云赛智联股份有限公司   \n",
       "3144  600654.SH  600654  ST中安  湖北  软件服务         中安科股份有限公司   \n",
       "...         ...     ...   ...  ..   ...               ...   \n",
       "2609  301263.SZ  301263  C泰恩康  广东  医药商业     广东泰恩康医药股份有限公司   \n",
       "4423  688193.SH  688193  仁度生物  上海  医疗保健    上海仁度生物科技股份有限公司   \n",
       "4514  688331.SH  688331  荣昌生物  山东  生物制药  荣昌生物制药(烟台)股份有限公司   \n",
       "4315  688048.SH  688048   N华芯  江苏   半导体  苏州长光华芯光电技术股份有限公司   \n",
       "4488  688295.SH  688295  中复神鹰  江苏    化纤     中复神鹰碳纤维股份有限公司   \n",
       "\n",
       "                                             英文全称  拼音缩写 市场类型（主板/创业板/科创板/CDR）  \\\n",
       "3                   Shenzhen Fountain Corporation  stxy                   主板   \n",
       "3141             Shanghai Feilo Acoustics Co.,Ltd  flyx                   主板   \n",
       "3143           Liaoning Shenhua Holdings Co., Ltd  shkg                   主板   \n",
       "3100                  INESA Intelligent Tech Inc.  yszl                   主板   \n",
       "3144                      China Security Co., Ltd  stza                   主板   \n",
       "...                                           ...   ...                  ...   \n",
       "2609  Guangdong Taienkang Pharmaceutical Co.,Ltd.   tek                  创业板   \n",
       "4423       Shanghai Rendu Biotechnology Co., Ltd.  rdsw                  科创板   \n",
       "4514                            Remegen Co., Ltd.  rcsw                  科创板   \n",
       "4315        Suzhou Everbright Photonics Co., Ltd.  cghx                  科创板   \n",
       "4488       Zhongfu Shenying Carbon Fiber Co.,Ltd.  zfsy                  科创板   \n",
       "\n",
       "     交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "3     SZSE  CNY                  L  19901210  None                     N  \n",
       "3141   SSE  CNY                  L  19901219  None                     N  \n",
       "3143   SSE  CNY                  L  19901219  None                     N  \n",
       "3100   SSE  CNY                  L  19901219  None                     N  \n",
       "3144   SSE  CNY                  L  19901219  None                     N  \n",
       "...    ...  ...                ...       ...   ...                   ...  \n",
       "2609  SZSE  CNY                  L  20220329  None                     N  \n",
       "4423   SSE  CNY                  L  20220330  None                     N  \n",
       "4514   SSE  CNY                  L  20220331  None                     N  \n",
       "4315   SSE  CNY                  L  20220401  None                     N  \n",
       "4488   SSE  CNY                  L  20220406  None                     N  \n",
       "\n",
       "[4770 rows x 15 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.sort_values('上市日期')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c249d20-857a-4ceb-b05a-ac8c12d9fca3",
   "metadata": {},
   "source": [
    "# Pandas分析Tushare上市公司信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48d62301-3d38-4775-abb9-96ec2533ac0f",
   "metadata": {},
   "source": [
    "## 追忆老八股和老五股"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a99e9a0f-fb2f-4316-ad77-6fb384358b5a",
   "metadata": {},
   "source": [
    "**《中国股市记忆》** 央视版 61集 2010年为纪念中国资本市场成立20周年，央视财经频道隆重推出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12ad368a-4c52-4108-9e1e-b29779433483",
   "metadata": {},
   "source": [
    "深圳证券交易所（Shenzhen Stock Exchange，中文简称：深交所）成立于1990年12月1日  \n",
    "上海证券交易所（英文：Shanghai Stock Exchange，中文简称：上交所）成立于1990年11月26日"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9771b60a-f6d8-4268-9891-d657c8e5f84b",
   "metadata": {},
   "source": [
    "**老五股**：000001深发展、000002深万科、000003深金田、000004深安达、000005深原野  \n",
    "**老八股**：600653申华控股、600654飞乐股份、600655豫园商城、600602真空电子、600656浙江凤凰、600651飞乐音响、600652爱使股份、600601延中实业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2f3efb4-ebfb-4b23-8244-9e15ac4e28ee",
   "metadata": {},
   "source": [
    "### 替换表头的名字——columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "992ccb27-452a-4177-9ac4-e9cc2cb9bbfa",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "all_fields = 'ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs'\n",
    "data = pro.stock_basic(exchange='', list_status='L', fields=all_fields)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "cecfab04-9156-4235-b7e4-d62fc6995846",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ts_code', 'symbol', 'name', 'area', 'industry', 'fullname', 'enname',\n",
       "       'cnspell', 'market', 'exchange', 'curr_type', 'list_status',\n",
       "       'list_date', 'delist_date', 'is_hs'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48526eeb-4eb8-46da-b5c1-1ff614078fcb",
   "metadata": {},
   "source": [
    "### 列表的概念——容器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "4c0b84c8-10a5-4fcb-a825-998376981cff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[0, 1, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "c9df7840-11f3-4258-b280-e4efb18fe8ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.columns = ['TS代码', '股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写', '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期', '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "35f16648-4f21-4a10-83ed-d58f1fad54b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['TS代码', '股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写',\n",
       "       '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期',\n",
       "       '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da36ba01-437c-4ebc-9bdd-e6170a952c0e",
   "metadata": {},
   "source": [
    "### 查看数据量——shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "f3e57f0e-d157-4f26-8922-1c602c543cd0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4770, 15)"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e67148a3-9e77-46e1-ba4b-ad52bfb1e427",
   "metadata": {},
   "source": [
    "### 只看头看尾——head、tail"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "bd3eb517-33b6-4b34-b6a3-e43db1dcafbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>平安银行股份有限公司</td>\n",
       "      <td>Ping An Bank Co., Ltd.</td>\n",
       "      <td>payh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910403</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称  地域 所属行业        股票全称                    英文全称  拼音缩写  \\\n",
       "0  000001.SZ  000001  平安银行  深圳   银行  平安银行股份有限公司  Ping An Bank Co., Ltd.  payh   \n",
       "\n",
       "  市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "0                   主板  SZSE  CNY                  L  19910403  None   \n",
       "\n",
       "  是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "0                     S  "
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "8e272e8f-393e-4d4e-b300-3404b8a208e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4769</th>\n",
       "      <td>689009.SH</td>\n",
       "      <td>689009</td>\n",
       "      <td>九号公司-WD</td>\n",
       "      <td>北京</td>\n",
       "      <td>摩托车</td>\n",
       "      <td>九号有限公司</td>\n",
       "      <td>Ninebot Limited</td>\n",
       "      <td>jhgs-wd</td>\n",
       "      <td>CDR</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20201029</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码     股票名称  地域 所属行业    股票全称             英文全称     拼音缩写  \\\n",
       "4769  689009.SH  689009  九号公司-WD  北京  摩托车  九号有限公司  Ninebot Limited  jhgs-wd   \n",
       "\n",
       "     市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "4769                  CDR   SSE  CNY                  L  20201029  None   \n",
       "\n",
       "     是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "4769                  None  "
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.tail(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ebbd5f3-57e3-4bb6-8ea7-6a94acc4c171",
   "metadata": {},
   "source": [
    "### 切片获取Series——loc、iloc"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02f4abec-d4cb-4e21-a5af-5b86f136503c",
   "metadata": {},
   "source": [
    "#### loc 对index和columns的切分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "c03b42cf-4bf5-4b3b-b037-90a5e6e1bd75",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       SZSE\n",
       "1       SZSE\n",
       "2       SZSE\n",
       "3       SZSE\n",
       "4       SZSE\n",
       "        ... \n",
       "4765     BSE\n",
       "4766     BSE\n",
       "4767     BSE\n",
       "4768     BSE\n",
       "4769     SSE\n",
       "Name: 交易所代码, Length: 4770, dtype: object"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[:,'交易所代码']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "2c0b8c21-112a-42d6-a21c-34d862db0bbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       SZSE\n",
       "1       SZSE\n",
       "2       SZSE\n",
       "3       SZSE\n",
       "4       SZSE\n",
       "        ... \n",
       "4765     BSE\n",
       "4766     BSE\n",
       "4767     BSE\n",
       "4768     BSE\n",
       "4769     SSE\n",
       "Name: 交易所代码, Length: 4770, dtype: object"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['交易所代码']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "ba38e5b1-5878-49df-9aab-a902c3dcb763",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TS代码                                  000001.SZ\n",
       "股票代码                                     000001\n",
       "股票名称                                       平安银行\n",
       "地域                                           深圳\n",
       "所属行业                                         银行\n",
       "股票全称                                 平安银行股份有限公司\n",
       "英文全称                     Ping An Bank Co., Ltd.\n",
       "拼音缩写                                       payh\n",
       "市场类型（主板/创业板/科创板/CDR）                         主板\n",
       "交易所代码                                      SZSE\n",
       "交易货币                                        CNY\n",
       "上市状态 L上市 D退市 P暂停上市                            L\n",
       "上市日期                                   19910403\n",
       "退市日期                                       None\n",
       "是否沪深港通标的，N否 H沪股通 S深股通                         S\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[0,:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a53066c-3060-4cdf-8d93-71b62779b767",
   "metadata": {},
   "source": [
    "#### iloc——绝对位置的切"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "61759861-6da4-4950-bf51-af22eb3f6eae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       SZSE\n",
       "1       SZSE\n",
       "2       SZSE\n",
       "3       SZSE\n",
       "4       SZSE\n",
       "        ... \n",
       "4765     BSE\n",
       "4766     BSE\n",
       "4767     BSE\n",
       "4768     BSE\n",
       "4769     SSE\n",
       "Name: 交易所代码, Length: 4770, dtype: object"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[:, 9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "5b5d3d2e-b81b-4b96-92fe-c6be9c37a7c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TS代码                                  000001.SZ\n",
       "股票代码                                     000001\n",
       "股票名称                                       平安银行\n",
       "地域                                           深圳\n",
       "所属行业                                         银行\n",
       "股票全称                                 平安银行股份有限公司\n",
       "英文全称                     Ping An Bank Co., Ltd.\n",
       "拼音缩写                                       payh\n",
       "市场类型（主板/创业板/科创板/CDR）                         主板\n",
       "交易所代码                                      SZSE\n",
       "交易货币                                        CNY\n",
       "上市状态 L上市 D退市 P暂停上市                            L\n",
       "上市日期                                   19910403\n",
       "退市日期                                       None\n",
       "是否沪深港通标的，N否 H沪股通 S深股通                         S\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[0, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb7cb6b2-aa54-4cea-8f85-900f6729294c",
   "metadata": {},
   "source": [
    "#### 关于:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04022f9e-f4a7-4d47-8335-db99d9cbf344",
   "metadata": {},
   "source": [
    "##### : 左闭右开"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "3b1158ea-2520-4e92-9c42-91836819beb7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码\n",
       "0  000001.SZ  000001\n",
       "1  000002.SZ  000002"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[:2, :2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "9a6827db-6e56-4bc3-a76c-4b9bbf23d16b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>000007.SZ</td>\n",
       "      <td>000007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4765</th>\n",
       "      <td>871642.BJ</td>\n",
       "      <td>871642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4766</th>\n",
       "      <td>871857.BJ</td>\n",
       "      <td>871857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4767</th>\n",
       "      <td>871981.BJ</td>\n",
       "      <td>871981</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4768</th>\n",
       "      <td>872925.BJ</td>\n",
       "      <td>872925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4769</th>\n",
       "      <td>689009.SH</td>\n",
       "      <td>689009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4769 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码\n",
       "1     000002.SZ  000002\n",
       "2     000004.SZ  000004\n",
       "3     000005.SZ  000005\n",
       "4     000006.SZ  000006\n",
       "5     000007.SZ  000007\n",
       "...         ...     ...\n",
       "4765  871642.BJ  871642\n",
       "4766  871857.BJ  871857\n",
       "4767  871981.BJ  871981\n",
       "4768  872925.BJ  872925\n",
       "4769  689009.SH  689009\n",
       "\n",
       "[4769 rows x 2 columns]"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[1:, :2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c0777ac-5033-481e-862e-e736e0711dba",
   "metadata": {},
   "source": [
    "##### []切分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "61e090cf-3af5-4351-b662-c32d18db33eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>平安银行股份有限公司</td>\n",
       "      <td>Ping An Bank Co., Ltd.</td>\n",
       "      <td>payh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910403</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国华网安</td>\n",
       "      <td>深圳</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>深圳国华网安科技股份有限公司</td>\n",
       "      <td>Shenzhen Guohua Network Security Technology Co...</td>\n",
       "      <td>ghwa</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910114</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称  地域  所属行业            股票全称  \\\n",
       "0  000001.SZ  000001  平安银行  深圳    银行      平安银行股份有限公司   \n",
       "2  000004.SZ  000004  国华网安  深圳  软件服务  深圳国华网安科技股份有限公司   \n",
       "\n",
       "                                                英文全称  拼音缩写  \\\n",
       "0                             Ping An Bank Co., Ltd.  payh   \n",
       "2  Shenzhen Guohua Network Security Technology Co...  ghwa   \n",
       "\n",
       "  市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "0                   主板  SZSE  CNY                  L  19910403  None   \n",
       "2                   主板  SZSE  CNY                  L  19910114  None   \n",
       "\n",
       "  是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "0                     S  \n",
       "2                     N  "
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[[0, 2], :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "01434bf8-7e26-47d9-885a-277927c8ed8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>平安银行股份有限公司</td>\n",
       "      <td>Ping An Bank Co., Ltd.</td>\n",
       "      <td>payh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19910403</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称  地域 所属行业        股票全称                    英文全称  拼音缩写  \\\n",
       "0  000001.SZ  000001  平安银行  深圳   银行  平安银行股份有限公司  Ping An Bank Co., Ltd.  payh   \n",
       "\n",
       "  市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "0                   主板  SZSE  CNY                  L  19910403  None   \n",
       "\n",
       "  是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "0                     S  "
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[[0], :]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e41c1b4-f483-429f-9af3-585e9c0a61d5",
   "metadata": {},
   "source": [
    "##### 负数的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "8e8fbf60-2d98-423a-92a9-aca690a48cc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>L</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>L</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>L</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>L</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>L</td>\n",
       "      <td>19920427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4765</th>\n",
       "      <td>L</td>\n",
       "      <td>20210816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4766</th>\n",
       "      <td>L</td>\n",
       "      <td>20220228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4767</th>\n",
       "      <td>L</td>\n",
       "      <td>20211115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4768</th>\n",
       "      <td>L</td>\n",
       "      <td>20211025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4769</th>\n",
       "      <td>L</td>\n",
       "      <td>20201029</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4770 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     上市状态 L上市 D退市 P暂停上市      上市日期\n",
       "0                     L  19910403\n",
       "1                     L  19910129\n",
       "2                     L  19910114\n",
       "3                     L  19901210\n",
       "4                     L  19920427\n",
       "...                 ...       ...\n",
       "4765                  L  20210816\n",
       "4766                  L  20220228\n",
       "4767                  L  20211115\n",
       "4768                  L  20211025\n",
       "4769                  L  20201029\n",
       "\n",
       "[4770 rows x 2 columns]"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[:, -4:-2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d104ac3-7261-4fe2-b281-ee49ddd70667",
   "metadata": {},
   "source": [
    "### 查看去重结果——unique"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "4fe89aa6-7e94-4d94-b31f-4a156432bdfd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['SZSE', 'BSE', 'SSE'], dtype=object)"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['交易所代码'].unique()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56c5c292-6ce9-494b-bba6-8f4c0a381ff5",
   "metadata": {},
   "source": [
    "### 查看每个交易所的数量——value_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "91833c2b-d5bf-4a46-b620-cc52cac6fb36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SZSE    2610\n",
       "SSE     2071\n",
       "BSE       89\n",
       "Name: 交易所代码, dtype: int64"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['交易所代码'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d93d5a62-2825-4696-9bbb-6308e60f5c87",
   "metadata": {},
   "source": [
    "### 查看最早上市的股票——sort_values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "78101b0c-ae09-41d5-8b5f-7cf22d55d365",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>深圳世纪星源股份有限公司</td>\n",
       "      <td>Shenzhen Fountain Corporation</td>\n",
       "      <td>stxy</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901210</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3141</th>\n",
       "      <td>600651.SH</td>\n",
       "      <td>600651</td>\n",
       "      <td>飞乐音响</td>\n",
       "      <td>上海</td>\n",
       "      <td>电器仪表</td>\n",
       "      <td>上海飞乐音响股份有限公司</td>\n",
       "      <td>Shanghai Feilo Acoustics Co.,Ltd</td>\n",
       "      <td>flyx</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3143</th>\n",
       "      <td>600653.SH</td>\n",
       "      <td>600653</td>\n",
       "      <td>申华控股</td>\n",
       "      <td>辽宁</td>\n",
       "      <td>汽车服务</td>\n",
       "      <td>辽宁申华控股股份有限公司</td>\n",
       "      <td>Liaoning Shenhua Holdings Co., Ltd</td>\n",
       "      <td>shkg</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3100</th>\n",
       "      <td>600602.SH</td>\n",
       "      <td>600602</td>\n",
       "      <td>云赛智联</td>\n",
       "      <td>上海</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>云赛智联股份有限公司</td>\n",
       "      <td>INESA Intelligent Tech Inc.</td>\n",
       "      <td>yszl</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3144</th>\n",
       "      <td>600654.SH</td>\n",
       "      <td>600654</td>\n",
       "      <td>ST中安</td>\n",
       "      <td>湖北</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>中安科股份有限公司</td>\n",
       "      <td>China Security Co., Ltd</td>\n",
       "      <td>stza</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2609</th>\n",
       "      <td>301263.SZ</td>\n",
       "      <td>301263</td>\n",
       "      <td>C泰恩康</td>\n",
       "      <td>广东</td>\n",
       "      <td>医药商业</td>\n",
       "      <td>广东泰恩康医药股份有限公司</td>\n",
       "      <td>Guangdong Taienkang Pharmaceutical Co.,Ltd.</td>\n",
       "      <td>tek</td>\n",
       "      <td>创业板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220329</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4423</th>\n",
       "      <td>688193.SH</td>\n",
       "      <td>688193</td>\n",
       "      <td>仁度生物</td>\n",
       "      <td>上海</td>\n",
       "      <td>医疗保健</td>\n",
       "      <td>上海仁度生物科技股份有限公司</td>\n",
       "      <td>Shanghai Rendu Biotechnology Co., Ltd.</td>\n",
       "      <td>rdsw</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220330</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4514</th>\n",
       "      <td>688331.SH</td>\n",
       "      <td>688331</td>\n",
       "      <td>荣昌生物</td>\n",
       "      <td>山东</td>\n",
       "      <td>生物制药</td>\n",
       "      <td>荣昌生物制药(烟台)股份有限公司</td>\n",
       "      <td>Remegen Co., Ltd.</td>\n",
       "      <td>rcsw</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220331</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4315</th>\n",
       "      <td>688048.SH</td>\n",
       "      <td>688048</td>\n",
       "      <td>N华芯</td>\n",
       "      <td>江苏</td>\n",
       "      <td>半导体</td>\n",
       "      <td>苏州长光华芯光电技术股份有限公司</td>\n",
       "      <td>Suzhou Everbright Photonics Co., Ltd.</td>\n",
       "      <td>cghx</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220401</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4488</th>\n",
       "      <td>688295.SH</td>\n",
       "      <td>688295</td>\n",
       "      <td>中复神鹰</td>\n",
       "      <td>江苏</td>\n",
       "      <td>化纤</td>\n",
       "      <td>中复神鹰碳纤维股份有限公司</td>\n",
       "      <td>Zhongfu Shenying Carbon Fiber Co.,Ltd.</td>\n",
       "      <td>zfsy</td>\n",
       "      <td>科创板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20220406</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4770 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码  股票名称  地域  所属行业              股票全称  \\\n",
       "3     000005.SZ  000005  ST星源  深圳  环境保护      深圳世纪星源股份有限公司   \n",
       "3141  600651.SH  600651  飞乐音响  上海  电器仪表      上海飞乐音响股份有限公司   \n",
       "3143  600653.SH  600653  申华控股  辽宁  汽车服务      辽宁申华控股股份有限公司   \n",
       "3100  600602.SH  600602  云赛智联  上海  软件服务        云赛智联股份有限公司   \n",
       "3144  600654.SH  600654  ST中安  湖北  软件服务         中安科股份有限公司   \n",
       "...         ...     ...   ...  ..   ...               ...   \n",
       "2609  301263.SZ  301263  C泰恩康  广东  医药商业     广东泰恩康医药股份有限公司   \n",
       "4423  688193.SH  688193  仁度生物  上海  医疗保健    上海仁度生物科技股份有限公司   \n",
       "4514  688331.SH  688331  荣昌生物  山东  生物制药  荣昌生物制药(烟台)股份有限公司   \n",
       "4315  688048.SH  688048   N华芯  江苏   半导体  苏州长光华芯光电技术股份有限公司   \n",
       "4488  688295.SH  688295  中复神鹰  江苏    化纤     中复神鹰碳纤维股份有限公司   \n",
       "\n",
       "                                             英文全称  拼音缩写 市场类型（主板/创业板/科创板/CDR）  \\\n",
       "3                   Shenzhen Fountain Corporation  stxy                   主板   \n",
       "3141             Shanghai Feilo Acoustics Co.,Ltd  flyx                   主板   \n",
       "3143           Liaoning Shenhua Holdings Co., Ltd  shkg                   主板   \n",
       "3100                  INESA Intelligent Tech Inc.  yszl                   主板   \n",
       "3144                      China Security Co., Ltd  stza                   主板   \n",
       "...                                           ...   ...                  ...   \n",
       "2609  Guangdong Taienkang Pharmaceutical Co.,Ltd.   tek                  创业板   \n",
       "4423       Shanghai Rendu Biotechnology Co., Ltd.  rdsw                  科创板   \n",
       "4514                            Remegen Co., Ltd.  rcsw                  科创板   \n",
       "4315        Suzhou Everbright Photonics Co., Ltd.  cghx                  科创板   \n",
       "4488       Zhongfu Shenying Carbon Fiber Co.,Ltd.  zfsy                  科创板   \n",
       "\n",
       "     交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "3     SZSE  CNY                  L  19901210  None                     N  \n",
       "3141   SSE  CNY                  L  19901219  None                     N  \n",
       "3143   SSE  CNY                  L  19901219  None                     N  \n",
       "3100   SSE  CNY                  L  19901219  None                     N  \n",
       "3144   SSE  CNY                  L  19901219  None                     N  \n",
       "...    ...  ...                ...       ...   ...                   ...  \n",
       "2609  SZSE  CNY                  L  20220329  None                     N  \n",
       "4423   SSE  CNY                  L  20220330  None                     N  \n",
       "4514   SSE  CNY                  L  20220331  None                     N  \n",
       "4315   SSE  CNY                  L  20220401  None                     N  \n",
       "4488   SSE  CNY                  L  20220406  None                     N  \n",
       "\n",
       "[4770 rows x 15 columns]"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.sort_values('上市日期')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "017a65e0-78a5-403a-863a-ed39e17e03ca",
   "metadata": {},
   "source": [
    "### Jupyter注释提示——Shift+Tab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "934f2e51-58f0-427c-8934-384ead16e4e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.sort_values('上市日期')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "fd81f40c-1f48-449b-a156-743985486468",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "7cd810a9-0b8e-4add-990b-070078609430",
   "metadata": {},
   "outputs": [],
   "source": [
    ">>> df = pd.DataFrame({\n",
    "...     'col1': ['A', 'A', 'B', np.nan, 'D', 'C'],\n",
    "...     'col2': [2, 1, 9, 8, 7, 4],\n",
    "...     'col3': [0, 1, 9, 4, 2, 3],\n",
    "...     'col4': ['a', 'B', 'c', 'D', 'e', 'F']\n",
    "... })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "dd7c2ca1-3734-490b-8d1b-e6dc1efb17bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>c</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>C</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>D</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>e</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  col1  col2  col3 col4\n",
       "0    A     2     0    a\n",
       "1    A     1     1    B\n",
       "2    B     9     9    c\n",
       "5    C     4     3    F\n",
       "4    D     7     2    e\n",
       "3  NaN     8     4    D"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by=['col1'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "c7dd8577-f347-42ea-904b-fb5ae154d043",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>c</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>C</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>D</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>e</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  col1  col2  col3 col4\n",
       "1    A     1     1    B\n",
       "0    A     2     0    a\n",
       "2    B     9     9    c\n",
       "5    C     4     3    F\n",
       "4    D     7     2    e\n",
       "3  NaN     8     4    D"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by=['col1', 'col2'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83bcc463-5417-437d-8c78-eba2f773f892",
   "metadata": {},
   "source": [
    "### 结合排序和head和切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "c9c05fe4-0692-4f1f-9706-cf0984a89b3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3       000005\n",
       "3141    600651\n",
       "3143    600653\n",
       "3100    600602\n",
       "3144    600654\n",
       "3142    600652\n",
       "3099    600601\n",
       "2       000004\n",
       "1       000002\n",
       "0       000001\n",
       "7       000009\n",
       "3101    600603\n",
       "10      000012\n",
       "Name: 股票代码, dtype: object"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.sort_values('上市日期').head(8+5).loc[:, '股票代码']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5978803-1e87-4059-bf56-71fb7e44815b",
   "metadata": {},
   "source": [
    "**老五股**：000001深发展、000002深万科、000003深金田、000004深安达、000005深原野  \n",
    "**老八股**：600653申华控股、600654飞乐股份、600655豫园商城、600602真空电子、600656浙江凤凰、600651飞乐音响、600652爱使股份、600601延中实业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "910e88a4-73dc-4046-b1c7-5d05ca912110",
   "metadata": {},
   "source": [
    "### 分交易所来看——条件切片"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "752ab33e-bd3c-4316-b4ed-b7df3c4497ef",
   "metadata": {},
   "source": [
    "#### 布尔型的series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "24c67c97-b305-460c-89cb-e2abb3bf9460",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       False\n",
       "1       False\n",
       "2       False\n",
       "3       False\n",
       "4       False\n",
       "        ...  \n",
       "4765    False\n",
       "4766    False\n",
       "4767    False\n",
       "4768    False\n",
       "4769     True\n",
       "Name: 交易所代码, Length: 4770, dtype: bool"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['交易所代码'] == 'SSE'"
   ]
  },
  {
   "cell_type": "raw",
   "id": "31b0c328-be84-447d-9372-1c2efa9507c2",
   "metadata": {},
   "source": [
    "data.loc[data['交易所代码'] == 'SSE', :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "b6b48f5a-3176-4636-9a29-d0830278fd26",
   "metadata": {},
   "outputs": [],
   "source": [
    "sse_data = data[data['交易所代码'] == 'SSE']\n",
    "szse_data = data[data['交易所代码'] == 'SZSE']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "bef3a5b7-3e0f-41d3-81f0-573164f80cb7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2616</th>\n",
       "      <td>600000.SH</td>\n",
       "      <td>600000</td>\n",
       "      <td>浦发银行</td>\n",
       "      <td>上海</td>\n",
       "      <td>银行</td>\n",
       "      <td>上海浦东发展银行股份有限公司</td>\n",
       "      <td>Shanghai Pudong Development Bank Co.,Ltd.</td>\n",
       "      <td>pfyh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19991110</td>\n",
       "      <td>None</td>\n",
       "      <td>H</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2617</th>\n",
       "      <td>600004.SH</td>\n",
       "      <td>600004</td>\n",
       "      <td>白云机场</td>\n",
       "      <td>广东</td>\n",
       "      <td>机场</td>\n",
       "      <td>广州白云国际机场股份有限公司</td>\n",
       "      <td>Guangzhou Baiyun International Airport Company...</td>\n",
       "      <td>byjc</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20030428</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2618</th>\n",
       "      <td>600006.SH</td>\n",
       "      <td>600006</td>\n",
       "      <td>东风汽车</td>\n",
       "      <td>湖北</td>\n",
       "      <td>汽车整车</td>\n",
       "      <td>东风汽车股份有限公司</td>\n",
       "      <td>Dongfeng Automobile Co.Lt</td>\n",
       "      <td>dfqc</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19990727</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码  股票名称  地域  所属行业            股票全称  \\\n",
       "2616  600000.SH  600000  浦发银行  上海    银行  上海浦东发展银行股份有限公司   \n",
       "2617  600004.SH  600004  白云机场  广东    机场  广州白云国际机场股份有限公司   \n",
       "2618  600006.SH  600006  东风汽车  湖北  汽车整车      东风汽车股份有限公司   \n",
       "\n",
       "                                                   英文全称  拼音缩写  \\\n",
       "2616          Shanghai Pudong Development Bank Co.,Ltd.  pfyh   \n",
       "2617  Guangzhou Baiyun International Airport Company...  byjc   \n",
       "2618                          Dongfeng Automobile Co.Lt  dfqc   \n",
       "\n",
       "     市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "2616                   主板   SSE  CNY                  L  19991110  None   \n",
       "2617                   主板   SSE  CNY                  L  20030428  None   \n",
       "2618                   主板   SSE  CNY                  L  19990727  None   \n",
       "\n",
       "     是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "2616                     H  \n",
       "2617                     N  \n",
       "2618                     N  "
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sse_data.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "462f8305-1131-4d3c-bb02-9a32aaca256c",
   "metadata": {},
   "source": [
    "#### jupyter技巧—— . + tab / tab 提示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bf2d279-9cc5-4b70-b85c-feac96240e67",
   "metadata": {},
   "outputs": [],
   "source": [
    "sse_data.sort_values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9aba58e5-b892-47b3-b7f5-dc6204bf5272",
   "metadata": {},
   "outputs": [],
   "source": [
    "sse_data."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95845940-25a1-428d-8d60-ab2aac08633f",
   "metadata": {},
   "source": [
    "#### 查看各交易所排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "474f81e4-c177-462f-b242-c9a1574e320e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "483    600601\n",
       "525    600651\n",
       "527    600653\n",
       "528    600654\n",
       "526    600652\n",
       "484    600602\n",
       "485    600603\n",
       "488    600606\n",
       "Name: 股票代码, dtype: object"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sse_data.sort_values('上市日期').head(8).iloc[:, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "2817fa25-7d90-4fb4-8336-db1aa19d4db6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    000005\n",
       "2    000004\n",
       "1    000002\n",
       "0    000001\n",
       "7    000009\n",
       "Name: 股票代码, dtype: object"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "szse_data.sort_values('上市日期').head(5).iloc[:, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "981c6f8d-1e70-450d-b731-c4ab6d0e0732",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>深圳世纪星源股份有限公司</td>\n",
       "      <td>Shenzhen Fountain Corporation</td>\n",
       "      <td>stxy</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901210</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称  地域  所属行业          股票全称  \\\n",
       "3  000005.SZ  000005  ST星源  深圳  环境保护  深圳世纪星源股份有限公司   \n",
       "\n",
       "                            英文全称  拼音缩写 市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币  \\\n",
       "3  Shenzhen Fountain Corporation  stxy                   主板  SZSE  CNY   \n",
       "\n",
       "  上市状态 L上市 D退市 P暂停上市      上市日期  退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "3                  L  19901210  None                     N  "
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.sort_values('上市日期').head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54c8f402-6673-4fc7-9524-5445c1d1604a",
   "metadata": {},
   "source": [
    "**老五股**：000001深发展、000002深万科、000003深金田、000004深安达、000005深原野  \n",
    "**老八股**：600653申华控股、600654飞乐股份、600655豫园商城、600602真空电子、600656浙江凤凰、600651飞乐音响、600652爱使股份、600601延中实业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2dcf6828-d9fd-431b-9ffc-c73c18a13225",
   "metadata": {},
   "source": [
    "#### 查看有无改代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "1556fc80-98a2-4ecf-9113-353023594f8a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [TS代码, 股票代码, 股票名称, 地域, 所属行业, 股票全称, 英文全称, 拼音缩写, 市场类型（主板/创业板/科创板/CDR）, 交易所代码, 交易货币, 上市状态 L上市 D退市 P暂停上市, 上市日期, 退市日期, 是否沪深港通标的，N否 H沪股通 S深股通]\n",
       "Index: []"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['股票代码'] == '000003']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "6b3c505a-88ef-4468-8923-e0781a6c11a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3145</th>\n",
       "      <td>600655.SH</td>\n",
       "      <td>600655</td>\n",
       "      <td>豫园股份</td>\n",
       "      <td>上海</td>\n",
       "      <td>百货</td>\n",
       "      <td>上海豫园旅游商城(集团)股份有限公司</td>\n",
       "      <td>Shanghai Yuyuan Tourist Mart( Group) Co., Ltd.</td>\n",
       "      <td>yygf</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19920902</td>\n",
       "      <td>None</td>\n",
       "      <td>H</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码  股票名称  地域 所属行业                股票全称  \\\n",
       "3145  600655.SH  600655  豫园股份  上海   百货  上海豫园旅游商城(集团)股份有限公司   \n",
       "\n",
       "                                                英文全称  拼音缩写  \\\n",
       "3145  Shanghai Yuyuan Tourist Mart( Group) Co., Ltd.  yygf   \n",
       "\n",
       "     市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "3145                   主板   SSE  CNY                  L  19920902  None   \n",
       "\n",
       "     是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "3145                     H  "
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['股票代码'] == '600655']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "d6de28f3-84d1-4b7d-b661-6418da4e2626",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [TS代码, 股票代码, 股票名称, 地域, 所属行业, 股票全称, 英文全称, 拼音缩写, 市场类型（主板/创业板/科创板/CDR）, 交易所代码, 交易货币, 上市状态 L上市 D退市 P暂停上市, 上市日期, 退市日期, 是否沪深港通标的，N否 H沪股通 S深股通]\n",
       "Index: []"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['股票代码'] == '600656']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d823428-18a0-4988-b181-840bfae1a62a",
   "metadata": {},
   "source": [
    "### 索引重排——index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "325ff9e2-eb52-4239-becf-7ed72d88c136",
   "metadata": {},
   "source": [
    "#### 不重排切片的问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "5085b791-944b-4b73-87b4-3fbd52f7a91e",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "0",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   3360\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3361\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcasted_key\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   3362\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 0",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32mC:\\Users\\ADMINI~1\\AppData\\Local\\Temp/ipykernel_12464/4092213277.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msse_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m    923\u001b[0m                 \u001b[1;32mwith\u001b[0m \u001b[0msuppress\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mKeyError\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mIndexError\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    924\u001b[0m                     \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtakeable\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_takeable\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 925\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_tuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    926\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    927\u001b[0m             \u001b[1;31m# we by definition only have the 0th axis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_tuple\u001b[1;34m(self, tup)\u001b[0m\n\u001b[0;32m   1098\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_getitem_tuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtup\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1099\u001b[0m         \u001b[1;32mwith\u001b[0m \u001b[0msuppress\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mIndexingError\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1100\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_lowerdim\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtup\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1101\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1102\u001b[0m         \u001b[1;31m# no multi-index, so validate all of the indexers\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_lowerdim\u001b[1;34m(self, tup)\u001b[0m\n\u001b[0;32m    836\u001b[0m                 \u001b[1;31m# We don't need to check for tuples here because those are\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    837\u001b[0m                 \u001b[1;31m#  caught by the _is_nested_tuple_indexer check above.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 838\u001b[1;33m                 \u001b[0msection\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    839\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    840\u001b[0m                 \u001b[1;31m# We should never have a scalar section here, because\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1162\u001b[0m         \u001b[1;31m# fall thru to straight lookup\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1163\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_key\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1164\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_label\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1165\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1166\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_get_slice_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslice_obj\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mslice\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_get_label\u001b[1;34m(self, label, axis)\u001b[0m\n\u001b[0;32m   1111\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_get_label\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1112\u001b[0m         \u001b[1;31m# GH#5667 this will fail if the label is not present in the axis.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1113\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mxs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1114\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1115\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_handle_lowerdim_multi_index_axis0\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtup\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36mxs\u001b[1;34m(self, key, axis, level, drop_level)\u001b[0m\n\u001b[0;32m   3774\u001b[0m                 \u001b[1;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"Expected label or tuple of labels, got {key}\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3775\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3776\u001b[1;33m             \u001b[0mloc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   3777\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3778\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\conda\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   3361\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcasted_key\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3362\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3363\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   3364\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3365\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mis_scalar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0misna\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhasnans\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 0"
     ]
    }
   ],
   "source": [
    "sse_data.loc[0, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "0aa34765-5925-4608-8e3f-f4654e2d1cfd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TS代码                                                     600000.SH\n",
       "股票代码                                                        600000\n",
       "股票名称                                                          浦发银行\n",
       "地域                                                              上海\n",
       "所属行业                                                            银行\n",
       "股票全称                                                上海浦东发展银行股份有限公司\n",
       "英文全称                     Shanghai Pudong Development Bank Co.,Ltd.\n",
       "拼音缩写                                                          pfyh\n",
       "市场类型（主板/创业板/科创板/CDR）                                            主板\n",
       "交易所代码                                                          SSE\n",
       "交易货币                                                           CNY\n",
       "上市状态 L上市 D退市 P暂停上市                                               L\n",
       "上市日期                                                      19991110\n",
       "退市日期                                                          None\n",
       "是否沪深港通标的，N否 H沪股通 S深股通                                            H\n",
       "Name: 2616, dtype: object"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sse_data.iloc[0, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b20399f2-9cf3-470e-b4c8-d6b18560c900",
   "metadata": {},
   "source": [
    "#### 固定写法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "4c2f229c-9202-4d89-b5cf-bf287ec38846",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2071, 15)"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sse_data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "a7752d41-2883-4389-b993-615df2f08220",
   "metadata": {},
   "outputs": [],
   "source": [
    "sse_data.index = range(sse_data.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "33f0b29c-932d-457b-b56b-6203bdf276a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600000.SH</td>\n",
       "      <td>600000</td>\n",
       "      <td>浦发银行</td>\n",
       "      <td>上海</td>\n",
       "      <td>银行</td>\n",
       "      <td>上海浦东发展银行股份有限公司</td>\n",
       "      <td>Shanghai Pudong Development Bank Co.,Ltd.</td>\n",
       "      <td>pfyh</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19991110</td>\n",
       "      <td>None</td>\n",
       "      <td>H</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称  地域 所属行业            股票全称  \\\n",
       "0  600000.SH  600000  浦发银行  上海   银行  上海浦东发展银行股份有限公司   \n",
       "\n",
       "                                        英文全称  拼音缩写 市场类型（主板/创业板/科创板/CDR） 交易所代码  \\\n",
       "0  Shanghai Pudong Development Bank Co.,Ltd.  pfyh                   主板   SSE   \n",
       "\n",
       "  交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "0  CNY                  L  19991110  None                     H  "
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sse_data.head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c43c8595-f767-4cad-b4b6-592e38733485",
   "metadata": {},
   "source": [
    "### 又回到最初的起点——查看曾用名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "250e3099-56a4-4072-ad0f-0d6bdb4e4540",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>name</th>\n",
       "      <th>start_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>change_reason</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>20210506</td>\n",
       "      <td>None</td>\n",
       "      <td>ST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>世纪星源</td>\n",
       "      <td>20080625</td>\n",
       "      <td>None</td>\n",
       "      <td>撤销ST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>世纪星源</td>\n",
       "      <td>20080625</td>\n",
       "      <td>20210505</td>\n",
       "      <td>撤销ST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>20061009</td>\n",
       "      <td>20080624</td>\n",
       "      <td>摘G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>GST星源</td>\n",
       "      <td>20060731</td>\n",
       "      <td>20061008</td>\n",
       "      <td>完成股改</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>20040518</td>\n",
       "      <td>20060730</td>\n",
       "      <td>摘星</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>*ST星源</td>\n",
       "      <td>20030512</td>\n",
       "      <td>20040517</td>\n",
       "      <td>*ST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>20030416</td>\n",
       "      <td>20030511</td>\n",
       "      <td>ST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>世纪星源</td>\n",
       "      <td>19970101</td>\n",
       "      <td>20030415</td>\n",
       "      <td>改名</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>深星源A</td>\n",
       "      <td>19940103</td>\n",
       "      <td>19961231</td>\n",
       "      <td>改名</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>深原野A</td>\n",
       "      <td>19901210</td>\n",
       "      <td>19940102</td>\n",
       "      <td>其他</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ts_code   name start_date  end_date change_reason\n",
       "0   000005.SZ   ST星源   20210506      None            ST\n",
       "1   000005.SZ   世纪星源   20080625      None          撤销ST\n",
       "2   000005.SZ   世纪星源   20080625  20210505          撤销ST\n",
       "3   000005.SZ   ST星源   20061009  20080624            摘G\n",
       "4   000005.SZ  GST星源   20060731  20061008          完成股改\n",
       "5   000005.SZ   ST星源   20040518  20060730            摘星\n",
       "6   000005.SZ  *ST星源   20030512  20040517           *ST\n",
       "7   000005.SZ   ST星源   20030416  20030511            ST\n",
       "8   000005.SZ   世纪星源   19970101  20030415            改名\n",
       "9   000005.SZ   深星源A   19940103  19961231            改名\n",
       "10  000005.SZ   深原野A   19901210  19940102            其他"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.namechange(ts_code='000005.SZ', fields='ts_code,name,start_date,end_date,change_reason')\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25de9531-22ef-415d-8be4-0469841c8694",
   "metadata": {},
   "source": [
    "### 遗失的美好——查看退市的八股五股"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2bd5f7a-2feb-4787-a8b1-53852700a193",
   "metadata": {},
   "source": [
    "600656 000003"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "2ea2075b-6ffa-4eff-867d-1fdd57a5b7eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查询当前所有正常上市交易的股票列表\n",
    "all_fields = 'ts_code,symbol,name,area,industry,fullname,enname,cnspell,market,exchange,curr_type,list_status,list_date,delist_date,is_hs'\n",
    "exit_data = pro.stock_basic(exchange='', list_status='D', fields=all_fields)\n",
    "exit_data.columns = ['TS代码', '股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写', '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期', '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "a52e7b8a-64a3-45f6-a2a4-6743434ecb48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000003.SZ</td>\n",
       "      <td>000003</td>\n",
       "      <td>PT金田A(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>金田实业(集团)股份有限公司</td>\n",
       "      <td>Gintian Industry (Group) Co., Ltd.</td>\n",
       "      <td>ptjta</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19910703</td>\n",
       "      <td>20020614</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码      股票名称    地域  所属行业            股票全称  \\\n",
       "0  000003.SZ  000003  PT金田A(退)  None  None  金田实业(集团)股份有限公司   \n",
       "\n",
       "                                 英文全称   拼音缩写 市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币  \\\n",
       "0  Gintian Industry (Group) Co., Ltd.  ptjta                   主板  SZSE  CNY   \n",
       "\n",
       "  上市状态 L上市 D退市 P暂停上市      上市日期      退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "0                  D  19910703  20020614                     N  "
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exit_data.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "734ece40-3acf-4713-8e9f-bb9915da5175",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>600656.SH</td>\n",
       "      <td>600656</td>\n",
       "      <td>退博元(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>珠海市博元投资股份有限公司</td>\n",
       "      <td>Zhuhai Boyuan Investment Co., Ltd.</td>\n",
       "      <td>tsby</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19901219</td>\n",
       "      <td>20160513</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          TS代码    股票代码    股票名称    地域  所属行业           股票全称  \\\n",
       "113  600656.SH  600656  退博元(退)  None  None  珠海市博元投资股份有限公司   \n",
       "\n",
       "                                   英文全称  拼音缩写 市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币  \\\n",
       "113  Zhuhai Boyuan Investment Co., Ltd.  tsby                   主板   SSE  CNY   \n",
       "\n",
       "    上市状态 L上市 D退市 P暂停上市      上市日期      退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "113                  D  19901219  20160513                     N  "
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exit_data[exit_data['股票代码']=='600656']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "3e606384-56d9-4239-b2b4-7027891303d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>000508.SZ</td>\n",
       "      <td>000508</td>\n",
       "      <td>琼民源A(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>海南民源现代农业发展股份有限公司</td>\n",
       "      <td>Hainan Minyuan Modern Agriculture Development ...</td>\n",
       "      <td>qmya</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19930430</td>\n",
       "      <td>19990712</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107</th>\n",
       "      <td>600625.SH</td>\n",
       "      <td>600625</td>\n",
       "      <td>PT水仙(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>上海水仙电器股份有限公司</td>\n",
       "      <td>Shanghai Narcissus Electric Appliances Co.,Ltd.</td>\n",
       "      <td>ptsx</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19930106</td>\n",
       "      <td>20010423</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>000588.SZ</td>\n",
       "      <td>000588</td>\n",
       "      <td>PT粤金曼(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>广东国晟高科技股份有限公司</td>\n",
       "      <td>Guangdongguosheng High Technology Co.,Ltd</td>\n",
       "      <td>ptyjm</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19960123</td>\n",
       "      <td>20010615</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000015.SZ</td>\n",
       "      <td>000015</td>\n",
       "      <td>PT中浩A(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>深圳中浩(集团)股份有限公司</td>\n",
       "      <td>Shenzhen Zhonghao (Group) Company Limited</td>\n",
       "      <td>ptzha</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19920625</td>\n",
       "      <td>20011022</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>000556.SZ</td>\n",
       "      <td>000556</td>\n",
       "      <td>PT南洋(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>南洋航运集团股份有限公司</td>\n",
       "      <td>Nanyang Shipping Group Stock Holding Co.,Ltd.</td>\n",
       "      <td>ptny</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19940525</td>\n",
       "      <td>20020529</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>002359.SZ</td>\n",
       "      <td>002359</td>\n",
       "      <td>北讯退(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>北讯集团股份有限公司</td>\n",
       "      <td>Northcom Group Co., Ltd.</td>\n",
       "      <td>bxt</td>\n",
       "      <td>中小板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>20100210</td>\n",
       "      <td>20210723</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>300362.SZ</td>\n",
       "      <td>300362</td>\n",
       "      <td>天翔退(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>成都天翔环境股份有限公司</td>\n",
       "      <td>Chengdu Techcent Environment Co.,Ltd.</td>\n",
       "      <td>txt</td>\n",
       "      <td>创业板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>20140121</td>\n",
       "      <td>20210830</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>600068.SH</td>\n",
       "      <td>600068</td>\n",
       "      <td>葛洲坝(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>中国葛洲坝集团股份有限公司</td>\n",
       "      <td>China Gezhouba Group Company Limited</td>\n",
       "      <td>gzb</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19970526</td>\n",
       "      <td>20210913</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>600723.SH</td>\n",
       "      <td>600723</td>\n",
       "      <td>首商股份(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>北京首商集团股份有限公司</td>\n",
       "      <td>Beijing Capital Retailing Group Co., Ltd.</td>\n",
       "      <td>ssgf</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19960716</td>\n",
       "      <td>20211022</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>000780.SZ</td>\n",
       "      <td>000780</td>\n",
       "      <td>ST平能(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>内蒙古平庄能源股份有限公司</td>\n",
       "      <td>Inner Mongolia Pingzhuang Energy Resources Co....</td>\n",
       "      <td>stpn</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>D</td>\n",
       "      <td>19970606</td>\n",
       "      <td>20220124</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>147 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          TS代码    股票代码      股票名称    地域  所属行业              股票全称  \\\n",
       "11   000508.SZ  000508   琼民源A(退)  None  None  海南民源现代农业发展股份有限公司   \n",
       "107  600625.SH  600625   PT水仙(退)  None  None      上海水仙电器股份有限公司   \n",
       "24   000588.SZ  000588  PT粤金曼(退)  None  None     广东国晟高科技股份有限公司   \n",
       "2    000015.SZ  000015  PT中浩A(退)  None  None    深圳中浩(集团)股份有限公司   \n",
       "19   000556.SZ  000556   PT南洋(退)  None  None      南洋航运集团股份有限公司   \n",
       "..         ...     ...       ...   ...   ...               ...   \n",
       "59   002359.SZ  002359    北讯退(退)  None  None        北讯集团股份有限公司   \n",
       "72   300362.SZ  300362    天翔退(退)  None  None      成都天翔环境股份有限公司   \n",
       "80   600068.SH  600068    葛洲坝(退)  None  None     中国葛洲坝集团股份有限公司   \n",
       "124  600723.SH  600723   首商股份(退)  None  None      北京首商集团股份有限公司   \n",
       "43   000780.SZ  000780   ST平能(退)  None  None     内蒙古平庄能源股份有限公司   \n",
       "\n",
       "                                                  英文全称   拼音缩写  \\\n",
       "11   Hainan Minyuan Modern Agriculture Development ...   qmya   \n",
       "107    Shanghai Narcissus Electric Appliances Co.,Ltd.   ptsx   \n",
       "24           Guangdongguosheng High Technology Co.,Ltd  ptyjm   \n",
       "2            Shenzhen Zhonghao (Group) Company Limited  ptzha   \n",
       "19       Nanyang Shipping Group Stock Holding Co.,Ltd.   ptny   \n",
       "..                                                 ...    ...   \n",
       "59                            Northcom Group Co., Ltd.    bxt   \n",
       "72               Chengdu Techcent Environment Co.,Ltd.    txt   \n",
       "80                China Gezhouba Group Company Limited    gzb   \n",
       "124          Beijing Capital Retailing Group Co., Ltd.   ssgf   \n",
       "43   Inner Mongolia Pingzhuang Energy Resources Co....   stpn   \n",
       "\n",
       "    市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期      退市日期  \\\n",
       "11                    主板  SZSE  CNY                  D  19930430  19990712   \n",
       "107                   主板   SSE  CNY                  D  19930106  20010423   \n",
       "24                    主板  SZSE  CNY                  D  19960123  20010615   \n",
       "2                     主板  SZSE  CNY                  D  19920625  20011022   \n",
       "19                    主板  SZSE  CNY                  D  19940525  20020529   \n",
       "..                   ...   ...  ...                ...       ...       ...   \n",
       "59                   中小板  SZSE  CNY                  D  20100210  20210723   \n",
       "72                   创业板  SZSE  CNY                  D  20140121  20210830   \n",
       "80                    主板   SSE  CNY                  D  19970526  20210913   \n",
       "124                   主板   SSE  CNY                  D  19960716  20211022   \n",
       "43                    主板  SZSE  CNY                  D  19970606  20220124   \n",
       "\n",
       "    是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "11                      N  \n",
       "107                     N  \n",
       "24                      N  \n",
       "2                       N  \n",
       "19                      N  \n",
       "..                    ...  \n",
       "59                      N  \n",
       "72                      N  \n",
       "80                      N  \n",
       "124                     N  \n",
       "43                      N  \n",
       "\n",
       "[147 rows x 15 columns]"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exit_data.sort_values('退市日期')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bfeafbe-95c6-4271-80cb-9b46388cb34a",
   "metadata": {},
   "source": [
    "### Pandas中的VBA——apply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "id": "5c6ff7ad-c16f-4ace-9b16-25d344555acb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3099</th>\n",
       "      <td>600601.SH</td>\n",
       "      <td>600601</td>\n",
       "      <td>ST方科</td>\n",
       "      <td>上海</td>\n",
       "      <td>IT设备</td>\n",
       "      <td>方正科技集团股份有限公司</td>\n",
       "      <td>Founder Technology Group Co., Ltd.</td>\n",
       "      <td>stfk</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3100</th>\n",
       "      <td>600602.SH</td>\n",
       "      <td>600602</td>\n",
       "      <td>云赛智联</td>\n",
       "      <td>上海</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>云赛智联股份有限公司</td>\n",
       "      <td>INESA Intelligent Tech Inc.</td>\n",
       "      <td>yszl</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3141</th>\n",
       "      <td>600651.SH</td>\n",
       "      <td>600651</td>\n",
       "      <td>飞乐音响</td>\n",
       "      <td>上海</td>\n",
       "      <td>电器仪表</td>\n",
       "      <td>上海飞乐音响股份有限公司</td>\n",
       "      <td>Shanghai Feilo Acoustics Co.,Ltd</td>\n",
       "      <td>flyx</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3142</th>\n",
       "      <td>600652.SH</td>\n",
       "      <td>600652</td>\n",
       "      <td>*ST游久</td>\n",
       "      <td>上海</td>\n",
       "      <td>互联网</td>\n",
       "      <td>上海游久游戏股份有限公司</td>\n",
       "      <td>Shanghai U9 Game Co.,Ltd.</td>\n",
       "      <td>styj</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3143</th>\n",
       "      <td>600653.SH</td>\n",
       "      <td>600653</td>\n",
       "      <td>申华控股</td>\n",
       "      <td>辽宁</td>\n",
       "      <td>汽车服务</td>\n",
       "      <td>辽宁申华控股股份有限公司</td>\n",
       "      <td>Liaoning Shenhua Holdings Co., Ltd</td>\n",
       "      <td>shkg</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3144</th>\n",
       "      <td>600654.SH</td>\n",
       "      <td>600654</td>\n",
       "      <td>ST中安</td>\n",
       "      <td>湖北</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>中安科股份有限公司</td>\n",
       "      <td>China Security Co., Ltd</td>\n",
       "      <td>stza</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19901219</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3145</th>\n",
       "      <td>600655.SH</td>\n",
       "      <td>600655</td>\n",
       "      <td>豫园股份</td>\n",
       "      <td>上海</td>\n",
       "      <td>百货</td>\n",
       "      <td>上海豫园旅游商城(集团)股份有限公司</td>\n",
       "      <td>Shanghai Yuyuan Tourist Mart( Group) Co., Ltd.</td>\n",
       "      <td>yygf</td>\n",
       "      <td>主板</td>\n",
       "      <td>SSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19920902</td>\n",
       "      <td>None</td>\n",
       "      <td>H</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           TS代码    股票代码   股票名称  地域  所属行业                股票全称  \\\n",
       "3099  600601.SH  600601   ST方科  上海  IT设备        方正科技集团股份有限公司   \n",
       "3100  600602.SH  600602   云赛智联  上海  软件服务          云赛智联股份有限公司   \n",
       "3141  600651.SH  600651   飞乐音响  上海  电器仪表        上海飞乐音响股份有限公司   \n",
       "3142  600652.SH  600652  *ST游久  上海   互联网        上海游久游戏股份有限公司   \n",
       "3143  600653.SH  600653   申华控股  辽宁  汽车服务        辽宁申华控股股份有限公司   \n",
       "3144  600654.SH  600654   ST中安  湖北  软件服务           中安科股份有限公司   \n",
       "3145  600655.SH  600655   豫园股份  上海    百货  上海豫园旅游商城(集团)股份有限公司   \n",
       "\n",
       "                                                英文全称  拼音缩写  \\\n",
       "3099              Founder Technology Group Co., Ltd.  stfk   \n",
       "3100                     INESA Intelligent Tech Inc.  yszl   \n",
       "3141                Shanghai Feilo Acoustics Co.,Ltd  flyx   \n",
       "3142                       Shanghai U9 Game Co.,Ltd.  styj   \n",
       "3143              Liaoning Shenhua Holdings Co., Ltd  shkg   \n",
       "3144                         China Security Co., Ltd  stza   \n",
       "3145  Shanghai Yuyuan Tourist Mart( Group) Co., Ltd.  yygf   \n",
       "\n",
       "     市场类型（主板/创业板/科创板/CDR） 交易所代码 交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期  \\\n",
       "3099                   主板   SSE  CNY                  L  19901219  None   \n",
       "3100                   主板   SSE  CNY                  L  19901219  None   \n",
       "3141                   主板   SSE  CNY                  L  19901219  None   \n",
       "3142                   主板   SSE  CNY                  L  19901219  None   \n",
       "3143                   主板   SSE  CNY                  L  19901219  None   \n",
       "3144                   主板   SSE  CNY                  L  19901219  None   \n",
       "3145                   主板   SSE  CNY                  L  19920902  None   \n",
       "\n",
       "     是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "3099                     N  \n",
       "3100                     N  \n",
       "3141                     N  \n",
       "3142                     N  \n",
       "3143                     N  \n",
       "3144                     N  \n",
       "3145                     H  "
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['股票代码'].apply(lambda x : \n",
    "                  x in ['600653', '600655', '600654', '600602', '600656', '600651', '600652', '600601']\n",
    "                  )]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f749ef3-00f0-4bfc-a500-8fc0bec3acf6",
   "metadata": {},
   "source": [
    "**老五股**：000001深发展、000002深万科、000003深金田、000004深安达、000005深原野  \n",
    "**老八股**：600653申华控股、600654飞乐股份、600655豫园商城、600602真空电子、600656浙江凤凰、600651飞乐音响、600652爱使股份、600601延中实业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdd3efd1-3b70-4fd1-af81-269ee8cb5fec",
   "metadata": {},
   "source": [
    "## 上市公司分布分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b829a86c-eb01-40df-b9d3-accd18794fe0",
   "metadata": {},
   "source": [
    "地域\t所属行业分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70ce6247-f6f4-48d3-87e4-ef8641149eb8",
   "metadata": {},
   "source": [
    "### 上市公司地域分布——groupby"
   ]
  },
  {
   "cell_type": "raw",
   "id": "6ef9324e-bf80-4e16-9bcd-70939da73ed2",
   "metadata": {},
   "source": [
    "data['地域'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "364a1b61-7c93-4951-b984-d699d3ac8342",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "area_count = data.groupby('地域').count().iloc[:, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "id": "db837e2b-eab2-458c-ae90-531a26f33488",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "地域\n",
       "上海    389\n",
       "Name: TS代码, dtype: int64"
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "area_count.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78e02423-30a6-439e-a20a-e9f1d88cb7a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "地域\n",
       "上海     389\n",
       "云南      40\n",
       "内蒙      26\n",
       "北京     420\n",
       "吉林      47\n",
       "四川     156\n",
       "天津      64\n",
       "宁夏      15\n",
       "安徽     145\n",
       "山东     265\n",
       "山西      40\n",
       "广东     392\n",
       "广西      38\n",
       "新疆      57\n",
       "江苏     574\n",
       "江西      68\n",
       "河北      66\n",
       "河南      96\n",
       "浙江     612\n",
       "海南      34\n",
       "深圳     372\n",
       "湖北     126\n",
       "湖南     130\n",
       "甘肃      35\n",
       "福建     163\n",
       "西藏      21\n",
       "贵州      34\n",
       "辽宁      79\n",
       "重庆      60\n",
       "陕西      67\n",
       "青海      11\n",
       "黑龙江     38\n",
       "Name: TS代码, dtype: int64"
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "area_count"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec341a77-b9b9-4505-9751-62f3e783d19c",
   "metadata": {},
   "source": [
    "### 统计性描述——describe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "id": "cfb66b64-ef26-4236-b58e-776aae756197",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count     32.000000\n",
       "mean     146.250000\n",
       "std      167.277826\n",
       "min       11.000000\n",
       "25%       38.000000\n",
       "50%       66.500000\n",
       "75%      157.750000\n",
       "max      612.000000\n",
       "Name: TS代码, dtype: float64"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "area_count.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "id": "448f4770-3fc6-4080-9e5e-3969d6dc412c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count     32.000000\n",
       "mean     146.250000\n",
       "std      167.277826\n",
       "min       11.000000\n",
       "10%       26.800000\n",
       "20%       35.600000\n",
       "30%       40.000000\n",
       "40%       58.200000\n",
       "50%       66.500000\n",
       "75%      157.750000\n",
       "90%      391.700000\n",
       "95%      489.300000\n",
       "99%      600.220000\n",
       "max      612.000000\n",
       "Name: TS代码, dtype: float64"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "area_count.describe([.1, .2, .3, .4, .5, .75, .9, .95, .99])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c4b0a6c-4e5b-4f41-a83b-91d47e24ed2f",
   "metadata": {},
   "source": [
    "### 进行展示——pyecharts地图"
   ]
  },
  {
   "cell_type": "raw",
   "id": "1a1a191c-8754-4f0c-aa52-3c9d96e9720f",
   "metadata": {},
   "source": [
    "pyecharts==1.9.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "id": "8e99d07a-a03c-4b84-aa3e-142661cb44df",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Map\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.globals import CurrentConfig, NotebookType \n",
    "CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB\n",
    "\n",
    "area_count_dict = area_count.to_dict()\n",
    "area_count_dict['内蒙古'] =  area_count_dict['内蒙']\n",
    "map_data = [list(z) for z in zip(list(area_count_dict.keys()), list(area_count_dict.values()))]\n",
    "chinaMap = Map() \n",
    "chinaMap.add(series_name=\"公司数\", \n",
    "             data_pair=map_data,\n",
    "             maptype='china', \n",
    "            ) \n",
    "chinaMap.set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"上市公司分布数量\"),\n",
    "            visualmap_opts=opts.VisualMapOpts(\n",
    "                is_piecewise=True,\n",
    "                pieces=[\n",
    "                    {\"min\":0,\"max\":20,\"color\":\"cyan\"},\n",
    "                    {\"min\":20,\"max\":50, \"color\":\"yellow\"},\n",
    "                    {\"min\":50,\"max\":100, \"color\":\"orange\"},\n",
    "                    {\"min\":100,\"max\":300,\"color\":\"coral\"},\n",
    "                    {\"min\":300,\"max\":1000,\"color\":\"red\"},\n",
    "                ]\n",
    "            )\n",
    "        )\n",
    "chinaMap.load_javascript()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "id": "95335fc4-a732-46cb-aa6d-5af3737428a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "</head>\n",
       "<body>\n",
       "        <div id=\"c1a4d95be85e457c83fc0fe3ca11fa33\" class=\"chart-container\" style=\"width:900px; height:500px;\"></div>\n",
       "    <script>\n",
       "        var chart_c1a4d95be85e457c83fc0fe3ca11fa33 = echarts.init(\n",
       "            document.getElementById('c1a4d95be85e457c83fc0fe3ca11fa33'), 'white', {renderer: 'canvas'});\n",
       "        var option_c1a4d95be85e457c83fc0fe3ca11fa33 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u516c\\u53f8\\u6570\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 389\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\",\n",
       "                    \"value\": 40\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\",\n",
       "                    \"value\": 26\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 420\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 47\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": 156\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\",\n",
       "                    \"value\": 64\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u590f\",\n",
       "                    \"value\": 15\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": 145\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": 265\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": 40\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 392\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\",\n",
       "                    \"value\": 38\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u7586\",\n",
       "                    \"value\": 57\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 574\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 68\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": 66\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": 96\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 612\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\",\n",
       "                    \"value\": 34\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6df1\\u5733\",\n",
       "                    \"value\": 372\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": 126\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 130\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7518\\u8083\",\n",
       "                    \"value\": 35\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 163\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\",\n",
       "                    \"value\": 21\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": 34\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": 79\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": 60\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\",\n",
       "                    \"value\": 67\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d77\",\n",
       "                    \"value\": 11\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\",\n",
       "                    \"value\": 38\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\\u53e4\",\n",
       "                    \"value\": 26\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u516c\\u53f8\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u516c\\u53f8\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e0a\\u5e02\\u516c\\u53f8\\u5206\\u5e03\\u6570\\u91cf\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 14,\n",
       "        \"borderWidth\": 0,\n",
       "        \"pieces\": [\n",
       "            {\n",
       "                \"min\": 0,\n",
       "                \"max\": 20,\n",
       "                \"color\": \"cyan\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 20,\n",
       "                \"max\": 50,\n",
       "                \"color\": \"yellow\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 50,\n",
       "                \"max\": 100,\n",
       "                \"color\": \"orange\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 100,\n",
       "                \"max\": 300,\n",
       "                \"color\": \"coral\"\n",
       "            },\n",
       "            {\n",
       "                \"min\": 300,\n",
       "                \"max\": 1000,\n",
       "                \"color\": \"red\"\n",
       "            }\n",
       "        ]\n",
       "    }\n",
       "};\n",
       "        chart_c1a4d95be85e457c83fc0fe3ca11fa33.setOption(option_c1a4d95be85e457c83fc0fe3ca11fa33);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x280e7a7e8b0>"
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chinaMap.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51d638d9-0fcb-47f4-9b74-f4dc6211d9c1",
   "metadata": {},
   "source": [
    "### 奇怪的知识增加了"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2a4ad80-f7f1-4efb-b745-bcd1c0700480",
   "metadata": {},
   "source": [
    "http://finance.sina.com.cn/focus/hyzqsywg/?from=wap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "73dbc391-156f-4337-8353-05d5b1400522",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>地域</th>\n",
       "      <th>所属行业</th>\n",
       "      <th>股票全称</th>\n",
       "      <th>英文全称</th>\n",
       "      <th>拼音缩写</th>\n",
       "      <th>市场类型（主板/创业板/科创板/CDR）</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>交易货币</th>\n",
       "      <th>上市状态 L上市 D退市 P暂停上市</th>\n",
       "      <th>上市日期</th>\n",
       "      <th>退市日期</th>\n",
       "      <th>是否沪深港通标的，N否 H沪股通 S深股通</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>000159.SZ</td>\n",
       "      <td>000159</td>\n",
       "      <td>国际实业</td>\n",
       "      <td>新疆</td>\n",
       "      <td>石油贸易</td>\n",
       "      <td>新疆国际实业股份有限公司</td>\n",
       "      <td>Xinjiang International Industry Co.,Ltd</td>\n",
       "      <td>gjsy</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20000926</td>\n",
       "      <td>None</td>\n",
       "      <td>N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>000166.SZ</td>\n",
       "      <td>000166</td>\n",
       "      <td>申万宏源</td>\n",
       "      <td>新疆</td>\n",
       "      <td>证券</td>\n",
       "      <td>申万宏源集团股份有限公司</td>\n",
       "      <td>Shenwan Hongyuan Group Co.,Ltd.</td>\n",
       "      <td>swhy</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>20150126</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>000415.SZ</td>\n",
       "      <td>000415</td>\n",
       "      <td>渤海租赁</td>\n",
       "      <td>新疆</td>\n",
       "      <td>多元金融</td>\n",
       "      <td>渤海租赁股份有限公司</td>\n",
       "      <td>Bohai Leasing Co.,Ltd.</td>\n",
       "      <td>bhzl</td>\n",
       "      <td>主板</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>CNY</td>\n",
       "      <td>L</td>\n",
       "      <td>19960716</td>\n",
       "      <td>None</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         TS代码    股票代码  股票名称  地域  所属行业          股票全称  \\\n",
       "66  000159.SZ  000159  国际实业  新疆  石油贸易  新疆国际实业股份有限公司   \n",
       "67  000166.SZ  000166  申万宏源  新疆    证券  申万宏源集团股份有限公司   \n",
       "82  000415.SZ  000415  渤海租赁  新疆  多元金融    渤海租赁股份有限公司   \n",
       "\n",
       "                                       英文全称  拼音缩写 市场类型（主板/创业板/科创板/CDR） 交易所代码  \\\n",
       "66  Xinjiang International Industry Co.,Ltd  gjsy                   主板  SZSE   \n",
       "67          Shenwan Hongyuan Group Co.,Ltd.  swhy                   主板  SZSE   \n",
       "82                   Bohai Leasing Co.,Ltd.  bhzl                   主板  SZSE   \n",
       "\n",
       "   交易货币 上市状态 L上市 D退市 P暂停上市      上市日期  退市日期 是否沪深港通标的，N否 H沪股通 S深股通  \n",
       "66  CNY                  L  20000926  None                     N  \n",
       "67  CNY                  L  20150126  None                     S  \n",
       "82  CNY                  L  19960716  None                     S  "
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data['地域'] == '新疆'].head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "932cf28b-8b1d-4790-a8ab-9b3083d8e07c",
   "metadata": {},
   "source": [
    "### 梅开二度——上市公司行业分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "id": "cfd957f4-1ca3-4943-b61b-6757c03efa8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['TS代码', '股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写',\n",
       "       '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期',\n",
       "       '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "id": "2f48b958-00d1-4bac-b919-dcb08d5e2631",
   "metadata": {},
   "outputs": [],
   "source": [
    "industry_data = data.groupby('所属行业').count().iloc[:, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "id": "2052cefc-f0c8-4217-bb25-525c479aad1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "所属行业\n",
       "电器连锁      2\n",
       "公路        2\n",
       "林业        4\n",
       "商品城       4\n",
       "机场        4\n",
       "       ... \n",
       "专用机械    190\n",
       "化工原料    225\n",
       "元器件     234\n",
       "软件服务    248\n",
       "电气设备    251\n",
       "Name: TS代码, Length: 110, dtype: int64"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "industry_data.sort_values()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b062a4b1-6739-458a-a8ee-331e574e6379",
   "metadata": {},
   "source": [
    "## 上市公司的新维度分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e628dd57-150f-4a5d-a3c5-2104c58ea213",
   "metadata": {},
   "source": [
    "### 获取新数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "b7bc1fa4-4de8-4e11-bf68-9b2267813a14",
   "metadata": {},
   "outputs": [],
   "source": [
    "SZSE_basic = pro.stock_company(exchange='SZSE', fields='ts_code,exchange,chairman,manager,secretary,reg_capital,setup_date,province,city,introduction,website,email,office,employees,main_business,business_scope')\n",
    "BSE_basic = pro.stock_company(exchange='BSE', fields='ts_code,exchange,chairman,manager,secretary,reg_capital,setup_date,province,city,introduction,website,email,office,employees,main_business,business_scope')\n",
    "SSE_basic = pro.stock_company(exchange='SSE', fields='ts_code,exchange,chairman,manager,secretary,reg_capital,setup_date,province,city,introduction,website,email,office,employees,main_business,business_scope')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "id": "9fd659f8-5e1f-42bb-9310-632fd104808a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((2701, 16), (0, 16), (2146, 16))"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SZSE_basic.shape, BSE_basic.shape, SSE_basic.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "id": "9e6fc242-bdcd-4f9b-8c29-33e9b7a1a438",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SZSE    2610\n",
       "SSE     2071\n",
       "BSE       89\n",
       "Name: 交易所代码, dtype: int64"
      ]
     },
     "execution_count": 201,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['交易所代码'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b429fb5a-0781-498e-a2d3-79133c1b3d9b",
   "metadata": {},
   "source": [
    "### 合并三个交易所的新数据——concat"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e864196-496b-47d3-9048-70ac0d9118bb",
   "metadata": {},
   "source": [
    "concat合并依赖于index或columns相同！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "id": "9c395980-a955-4209-b7aa-82dd73b02fc5",
   "metadata": {},
   "outputs": [],
   "source": [
    "basic = pd.concat([SZSE_basic, BSE_basic, SSE_basic])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "id": "2d557c01-8dd7-4ee0-b96e-3f80c2ae634d",
   "metadata": {},
   "outputs": [],
   "source": [
    "basic.columns = ['股票代码','交易所代码','法人代表','总经理','董秘','注册资本','注册日期','所在省份','所在城市','公司介绍','公司主页','电子邮件','办公室','经营范围','员工人数','主要业务及产品']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "id": "7735eed2-c7ee-4bea-8c7c-0182fcbd17ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>股票代码</th>\n",
       "      <th>交易所代码</th>\n",
       "      <th>法人代表</th>\n",
       "      <th>总经理</th>\n",
       "      <th>董秘</th>\n",
       "      <th>注册资本</th>\n",
       "      <th>注册日期</th>\n",
       "      <th>所在省份</th>\n",
       "      <th>所在城市</th>\n",
       "      <th>公司介绍</th>\n",
       "      <th>公司主页</th>\n",
       "      <th>电子邮件</th>\n",
       "      <th>办公室</th>\n",
       "      <th>经营范围</th>\n",
       "      <th>员工人数</th>\n",
       "      <th>主要业务及产品</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>002392.SZ</td>\n",
       "      <td>SZSE</td>\n",
       "      <td>赵继增</td>\n",
       "      <td>赵伟</td>\n",
       "      <td>何枫</td>\n",
       "      <td>119049.0839</td>\n",
       "      <td>20001108</td>\n",
       "      <td>北京</td>\n",
       "      <td>北京市</td>\n",
       "      <td>公司从事钢铁、有色、石化、建材等高温工业用耐火材料的开发、生产、销售等，并承担高温热工装备用...</td>\n",
       "      <td>www.bjlirr.com</td>\n",
       "      <td>ir@bjlirr.com;caoxc@bjlirr.com;hef@bjlirr.com</td>\n",
       "      <td>北京市昌平区小汤山工业园</td>\n",
       "      <td>许可经营项目：制造耐火材料制品一般经营项目：耐火材料的技术开发、施工总承包；销售耐火材料制品...</td>\n",
       "      <td>2284.0</td>\n",
       "      <td>主要产品:不定形耐火材料,机压定型耐火制品,耐火预制件,功能耐火材料陶瓷纤维制品等五大系列耐...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        股票代码 交易所代码 法人代表 总经理  董秘         注册资本      注册日期 所在省份 所在城市  \\\n",
       "0  002392.SZ  SZSE  赵继增  赵伟  何枫  119049.0839  20001108   北京  北京市   \n",
       "\n",
       "                                                公司介绍            公司主页  \\\n",
       "0  公司从事钢铁、有色、石化、建材等高温工业用耐火材料的开发、生产、销售等，并承担高温热工装备用...  www.bjlirr.com   \n",
       "\n",
       "                                            电子邮件           办公室  \\\n",
       "0  ir@bjlirr.com;caoxc@bjlirr.com;hef@bjlirr.com  北京市昌平区小汤山工业园   \n",
       "\n",
       "                                                经营范围    员工人数  \\\n",
       "0  许可经营项目：制造耐火材料制品一般经营项目：耐火材料的技术开发、施工总承包；销售耐火材料制品...  2284.0   \n",
       "\n",
       "                                             主要业务及产品  \n",
       "0  主要产品:不定形耐火材料,机压定型耐火制品,耐火预制件,功能耐火材料陶瓷纤维制品等五大系列耐...  "
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "basic.head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e893735-a596-4e64-990c-be8bfb7f1a2f",
   "metadata": {},
   "source": [
    "### 再次合并新数据和老数据——concat"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf2d0747-58bc-4b3c-8a6a-0920eb799b10",
   "metadata": {},
   "source": [
    "#### 设置索引——set_index"
   ]
  },
  {
   "cell_type": "raw",
   "id": "fbedf946-aea8-45c8-9fac-805f2a5d592c",
   "metadata": {},
   "source": [
    "basic.head(1)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "49860cfa-7b34-486b-8563-f3ad5464b829",
   "metadata": {},
   "source": [
    "data.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "f3502f94-baa7-4f04-ad27-2508e98de239",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_ts = data.set_index('TS代码')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "78595822-d374-4501-a840-e3bdc2be3853",
   "metadata": {},
   "outputs": [],
   "source": [
    "basic_ts = basic.set_index('股票代码')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "dade8c31-b320-45a8-9ba1-59178087d12c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['股票代码', '股票名称', '地域', '所属行业', '股票全称', '英文全称', '拼音缩写',\n",
       "       '市场类型（主板/创业板/科创板/CDR）', '交易所代码', '交易货币', '上市状态 L上市 D退市 P暂停上市', '上市日期',\n",
       "       '退市日期', '是否沪深港通标的，N否 H沪股通 S深股通', '法人代表', '总经理', '董秘', '注册资本', '注册日期',\n",
       "       '所在省份', '所在城市', '公司介绍', '公司主页', '电子邮件', '办公室', '经营范围', '员工人数',\n",
       "       '主要业务及产品'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([ data_ts, basic_ts ]).columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "id": "cf8dcfe1-4305-49f7-9214-447ca0275a67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(9617, 28)"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([ data_ts, basic_ts ]).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "6f94d512-37b6-43de-a4c2-1846d12e4a9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_data_ts = pd.concat([ data_ts, basic_ts ], axis=1)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "0480d9e5-b5d6-40ff-97c0-39ea9a6acbcb",
   "metadata": {},
   "source": [
    "new_data_ts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fbaebc2-0f1a-4b3e-9c97-260c940f6260",
   "metadata": {},
   "source": [
    "### 更推荐的表关联方式——merge(SQL中的join)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "79aadac4-85db-4871-b798-1d13715de583",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_filter = data.loc[:, ['TS代码', '股票名称', '所属行业', '交易所代码']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "id": "4bcbd28e-f2ad-4b06-9d95-de0f8f486561",
   "metadata": {},
   "outputs": [],
   "source": [
    "merge_data = pd.merge(\n",
    "    left=data_filter,\n",
    "    right=basic,\n",
    "    how='left', # 'left', 'right', 'outer', 'inner'\n",
    "    left_on='TS代码',\n",
    "    right_on='股票代码'\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "daf6f868-e233-4e06-a721-c9fd7669288c",
   "metadata": {},
   "source": [
    "#### left：数据最终长度取决于左表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 238,
   "id": "2931db53-bc1e-4461-9d76-14afdce2e989",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((4770, 4), (4847, 16), (4770, 20))"
      ]
     },
     "execution_count": 238,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_filter.shape, basic.shape, merge_data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1e4966c-81b0-4254-907f-3f2ab21306d1",
   "metadata": {},
   "source": [
    "#### right：数据最终长度取决于右表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "5d616d22-04ca-4532-af29-c5cd6e86b7f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((4770, 4), (4847, 16), (4847, 20))"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_filter.shape, basic.shape, merge_data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a466a6d8-9305-49b7-aa71-1fdbbbc4f993",
   "metadata": {},
   "source": [
    "#### outer：数据最终长度取决于并集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "id": "0b651ca4-a74f-489a-8205-19f03318bf61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((4770, 4), (4847, 16), (4937, 20))"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_filter.shape, basic.shape, merge_data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "529dc3ca-4a77-4203-96d3-844ff2de2738",
   "metadata": {},
   "source": [
    "#### inner：数据最终长度取决于交集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "id": "6fa6067c-89ee-4e0d-b61b-50fda0293921",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((4770, 4), (4847, 16), (4680, 20))"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_filter.shape, basic.shape, merge_data.shape"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ba35366f-1d5d-48eb-99ca-bcdbe07632c0",
   "metadata": {},
   "source": [
    "merge_data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04cf2317-d3dc-441d-8cf8-c371eb2a3055",
   "metadata": {},
   "source": [
    "#### merge后结果会对重复的列名更换名字"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a73237c-0b12-4488-bacc-47c2c013a57e",
   "metadata": {},
   "source": [
    "### 查看各行业上市公司的员工数量——agg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "id": "31195d4e-7517-41d9-9c33-385aefeb7a6c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['TS代码', '股票名称', '所属行业', '交易所代码_x', '股票代码', '交易所代码_y', '法人代表', '总经理',\n",
       "       '董秘', '注册资本', '注册日期', '所在省份', '所在城市', '公司介绍', '公司主页', '电子邮件', '办公室',\n",
       "       '经营范围', '员工人数', '主要业务及产品'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 246,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merge_data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "id": "e4cd18dc-4549-4c5e-b482-0d90152eb512",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>注册资本</th>\n",
       "      <th>员工人数</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>所属行业</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>IT设备</th>\n",
       "      <td>3.399201e+06</td>\n",
       "      <td>189800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>专用机械</th>\n",
       "      <td>8.213765e+06</td>\n",
       "      <td>317844.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>中成药</th>\n",
       "      <td>6.715888e+06</td>\n",
       "      <td>287758.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>乳制品</th>\n",
       "      <td>1.539912e+06</td>\n",
       "      <td>107477.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>互联网</th>\n",
       "      <td>8.325279e+06</td>\n",
       "      <td>115044.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>银行</th>\n",
       "      <td>1.859917e+08</td>\n",
       "      <td>2468531.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陶瓷</th>\n",
       "      <td>4.655321e+05</td>\n",
       "      <td>20270.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>食品</th>\n",
       "      <td>5.919762e+06</td>\n",
       "      <td>340008.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>饲料</th>\n",
       "      <td>1.982679e+06</td>\n",
       "      <td>203155.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黄金</th>\n",
       "      <td>2.103072e+06</td>\n",
       "      <td>60045.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>110 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              注册资本       员工人数\n",
       "所属行业                         \n",
       "IT设备  3.399201e+06   189800.0\n",
       "专用机械  8.213765e+06   317844.0\n",
       "中成药   6.715888e+06   287758.0\n",
       "乳制品   1.539912e+06   107477.0\n",
       "互联网   8.325279e+06   115044.0\n",
       "...            ...        ...\n",
       "银行    1.859917e+08  2468531.0\n",
       "陶瓷    4.655321e+05    20270.0\n",
       "食品    5.919762e+06   340008.0\n",
       "饲料    1.982679e+06   203155.0\n",
       "黄金    2.103072e+06    60045.0\n",
       "\n",
       "[110 rows x 2 columns]"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merge_data.groupby('所属行业').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "id": "bd6827cd-4488-4708-9223-6789740ca0e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>交易所代码_x</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>交易所代码_y</th>\n",
       "      <th>法人代表</th>\n",
       "      <th>总经理</th>\n",
       "      <th>董秘</th>\n",
       "      <th>注册资本</th>\n",
       "      <th>注册日期</th>\n",
       "      <th>所在省份</th>\n",
       "      <th>所在城市</th>\n",
       "      <th>公司介绍</th>\n",
       "      <th>公司主页</th>\n",
       "      <th>电子邮件</th>\n",
       "      <th>办公室</th>\n",
       "      <th>经营范围</th>\n",
       "      <th>员工人数</th>\n",
       "      <th>主要业务及产品</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>所属行业</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>IT设备</th>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>专用机械</th>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "      <td>190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>中成药</th>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>68</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>乳制品</th>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>互联网</th>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>银行</th>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>40</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陶瓷</th>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>食品</th>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>81</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>83</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>饲料</th>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黄金</th>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>110 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      TS代码  股票名称  交易所代码_x  股票代码  交易所代码_y  法人代表  总经理   董秘  注册资本  注册日期  所在省份  \\\n",
       "所属行业                                                                         \n",
       "IT设备    39    39       39    39       39    39   39   39    39    39    39   \n",
       "专用机械   190   190      190   190      190   190  190  190   190   190   190   \n",
       "中成药     70    70       70    70       70    70   68   70    70    70    70   \n",
       "乳制品     16    16       16    16       16    16   15   16    16    16    16   \n",
       "互联网     82    82       82    82       82    82   82   82    82    82    82   \n",
       "...    ...   ...      ...   ...      ...   ...  ...  ...   ...   ...   ...   \n",
       "银行      42    42       42    42       42    42   40   42    42    42    42   \n",
       "陶瓷       7     7        7     7        7     7    7    7     7     7     7   \n",
       "食品      84    84       84    84       84    84   81   84    84    84    84   \n",
       "饲料      16    16       16    16       16    16   16   16    16    16    16   \n",
       "黄金      12    12       12    12       12    12   12   12    12    12    12   \n",
       "\n",
       "      所在城市  公司介绍  公司主页  电子邮件  办公室  经营范围  员工人数  主要业务及产品  \n",
       "所属行业                                                    \n",
       "IT设备    39    39    39    39   39    39    39       39  \n",
       "专用机械   190   190   190   190  190   190   190      190  \n",
       "中成药     70    70    70    70   70    70    70       70  \n",
       "乳制品     16    16    16    16   16    16    16       16  \n",
       "互联网     82    82    82    82   82    82    82       82  \n",
       "...    ...   ...   ...   ...  ...   ...   ...      ...  \n",
       "银行      42    42    42    42   42    42    42       42  \n",
       "陶瓷       7     7     7     7    7     7     7        7  \n",
       "食品      84    84    83    84   84    84    84       84  \n",
       "饲料      16    16    16    16   16    16    16       16  \n",
       "黄金      12    12    12    12   12    12    12       12  \n",
       "\n",
       "[110 rows x 19 columns]"
      ]
     },
     "execution_count": 253,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "merge_data.groupby('所属行业').count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "id": "47ccbcd0-33e8-4f2b-a4a6-03f601348b3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "industry_agg = merge_data.groupby('所属行业').agg({'员工人数': 'sum', '股票代码': 'count', '注册资本': 'sum'})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "364bb8d7-9fe2-4902-8d14-786293425a76",
   "metadata": {},
   "source": [
    "### 分析哪个行业的就业人员最多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "id": "8af5af6a-7d99-455b-947f-2269fb6aac72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>员工人数</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>注册资本</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>所属行业</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>林业</th>\n",
       "      <td>2243.0</td>\n",
       "      <td>4</td>\n",
       "      <td>2.634021e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>石油贸易</th>\n",
       "      <td>5113.0</td>\n",
       "      <td>7</td>\n",
       "      <td>4.196573e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>公路</th>\n",
       "      <td>5540.0</td>\n",
       "      <td>2</td>\n",
       "      <td>6.294890e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>红黄酒</th>\n",
       "      <td>12145.0</td>\n",
       "      <td>10</td>\n",
       "      <td>6.140207e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>批发业</th>\n",
       "      <td>15084.0</td>\n",
       "      <td>9</td>\n",
       "      <td>1.240759e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>电气设备</th>\n",
       "      <td>912255.0</td>\n",
       "      <td>251</td>\n",
       "      <td>2.317704e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>电信运营</th>\n",
       "      <td>980706.0</td>\n",
       "      <td>12</td>\n",
       "      <td>1.569269e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>元器件</th>\n",
       "      <td>1427125.0</td>\n",
       "      <td>234</td>\n",
       "      <td>2.072423e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>建筑工程</th>\n",
       "      <td>2028259.0</td>\n",
       "      <td>111</td>\n",
       "      <td>2.858963e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>银行</th>\n",
       "      <td>2468531.0</td>\n",
       "      <td>42</td>\n",
       "      <td>1.859917e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>110 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           员工人数  股票代码          注册资本\n",
       "所属行业                               \n",
       "林业       2243.0     4  2.634021e+05\n",
       "石油贸易     5113.0     7  4.196573e+05\n",
       "公路       5540.0     2  6.294890e+04\n",
       "红黄酒     12145.0    10  6.140207e+05\n",
       "批发业     15084.0     9  1.240759e+06\n",
       "...         ...   ...           ...\n",
       "电气设备   912255.0   251  2.317704e+07\n",
       "电信运营   980706.0    12  1.569269e+07\n",
       "元器件   1427125.0   234  2.072423e+07\n",
       "建筑工程  2028259.0   111  2.858963e+07\n",
       "银行    2468531.0    42  1.859917e+08\n",
       "\n",
       "[110 rows x 3 columns]"
      ]
     },
     "execution_count": 257,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "industry_agg.sort_values('员工人数')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "9e16ad04-46a0-4f9a-809b-389a8dc72d4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "所属行业\n",
       "林业         560.750000\n",
       "石油贸易       730.428571\n",
       "红黄酒       1214.500000\n",
       "园区开发      1343.375000\n",
       "互联网       1402.975610\n",
       "            ...      \n",
       "空运       37210.222222\n",
       "石油加工     49728.888889\n",
       "银行       58774.547619\n",
       "电信运营     81725.500000\n",
       "保险      114489.142857\n",
       "Length: 110, dtype: float64"
      ]
     },
     "execution_count": 264,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(industry_agg['员工人数']  / industry_agg['股票代码']).sort_values()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3619a05c-97c5-4eb8-9910-b8edef7cbf4a",
   "metadata": {},
   "source": [
    "### 查看各行业上市公司的注册资本/员工数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "id": "9e9f91d5-5d9e-4b69-8dcb-5127c3a49843",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "所属行业\n",
       "房产服务      5.446206\n",
       "超市连锁      6.674781\n",
       "医药商业      7.351048\n",
       "酒店餐饮      8.081380\n",
       "家居用品      8.159204\n",
       "           ...    \n",
       "林业      117.432939\n",
       "路桥      121.132080\n",
       "水力发电    132.350578\n",
       "多元金融    158.256677\n",
       "新型电力    238.398736\n",
       "Length: 110, dtype: float64"
      ]
     },
     "execution_count": 265,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(industry_agg['注册资本']  / industry_agg['员工人数']).sort_values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b1b672c-afdb-4f18-8335-b332ec3d8475",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc-autonumbering": true
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
